From 3f145a52eaee231e7a7bdf48068a0230ef007561 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 04:32:40 +0000 Subject: [PATCH 001/165] Auto-generated commit d833019f1446f7c54f5be81749dadbad57385a02 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 174 ++++ index.d.ts | 44 + index.mjs | 4 + index.mjs.map | 1 + package.json | 30 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3452 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..11a9417 --- /dev/null +++ b/README.md @@ -0,0 +1,174 @@ + + +# CLI + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Command-line interface namespace. + + + +
+ +## Usage + +```javascript +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +``` + +#### ns + +Command-line interface namespace. + +```javascript +var o = ns; +// returns {...} +``` + +The namespace contains the following: + + + +
+ +- [`CLI( [options] )`][@stdlib/cli/ctor]: command-line interface. + +
+ + + +
+ + + +
+ +## 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..5a95514 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 + +/* tslint:disable:max-line-length */ +/* tslint:disable:max-file-line-count */ + +import CLI = require( './../../ctor' ); + +/** +* Interface describing the `cli` namespace. +*/ +interface Namespace { + /** + * Command-line interface. + */ + CLI: typeof CLI; +} + +/** +* Command-line interface. +*/ +declare var ns: Namespace; + + +// EXPORTS // + +export = ns; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a0c4574 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function o(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})})),t}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);var me=de;export{he as CLI,me as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..07db93e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;4nBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAA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IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAVArH,EAmBAqH,GAAA,MAAAnF,IAKA,IAAAkF,GAAAC"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..26508b1 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "@stdlib/cli", + "version": "0.0.0", + "description": "Command-line interface.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/cli.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "utilities", + "utility", + "utils", + "util", + "cli", + "command-line", + "interface" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dbaf285 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 74a86a5f2861a4ba3decb31d5494bef663a69a77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:38:59 +0000 Subject: [PATCH 002/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 7ce739cb8b6d4e3100d63f398fb9cadd169dae93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:47:09 +0000 Subject: [PATCH 003/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a0c4574..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function o(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})})),t}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);var me=de;export{he as CLI,me as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 07db93e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;4nBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,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 - - - - - - - - RollUp Visualizer - - - -
- - - - - From eeaf4dc46ebcb359d5bb7c4a7715ff10057a3737 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:50:33 +0000 Subject: [PATCH 004/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 ---- ctor/benchmark/benchmark.js | 145 -- ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 ---- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----------- ctor/test/test.validate.js | 294 --- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 2717 insertions(+), 7066 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 b414f06..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:38:30.837Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index 97f777d..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var CLI = require( './main.js' ); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 060fdcd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import cli = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - cli; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1f1260e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..58dd8ea --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;wtBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,E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MZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6b302c2 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From f0b6f6f5866a25f9fc95842c905713b8012a8ab2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:20:42 +0000 Subject: [PATCH 005/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 19f5f24b46dd0e76ace3d5e20dba8cbd0dd4036f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 16:46:18 +0000 Subject: [PATCH 006/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1f1260e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 58dd8ea..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;wtBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,KAAOJ,EAAQI,KACM,iBAAdL,EAAKK,MACT,IAAIH,UAAWX,EAAQ,8DAA+D,OAAQS,EAAKK,OAGvGZ,EAAWU,KAAMF,EAAS,aAC9BD,EAAKM,QAAUL,EAAQK,QACM,iBAAjBN,EAAKM,SACT,IAAIJ,UAAWX,EAAQ,8DAA+D,UAAWS,EAAKM,UAG1Gb,EAAWU,KAAMF,EA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ACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6b302c2..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e759ead66a12e00b416cd56fd7bfe72d839b44ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 16:49:09 +0000 Subject: [PATCH 007/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 ---- ctor/benchmark/benchmark.js | 145 -- ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 ---- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----------- ctor/test/test.validate.js | 294 --- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 2717 insertions(+), 7105 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 63aa51c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:42:03.831Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index 97f777d..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var CLI = require( './main.js' ); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 060fdcd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import cli = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - cli; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5ba40cd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,KAAOJ,EAAQI,KACM,iBAAdL,EAAKK,MACT,IAAIH,UAAWX,EAAQ,8DAA+D,OAAQS,EAAKK,OAGvGZ,EAAWU,KAAMF,EAAS,aAC9BD,EAA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B,IAEpGI,GAAUL,GAAMC,QANfI,GAAUL,GAAM,MAoClBoE,GAAaK,GAAI/F,UAAW,SAAS,SAAkB4G,EAAOrF,GAC7D,IAAIuF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3d7a2ce --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 5b23265b241f61a682356eeccbcc72ada6394e1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:11:23 +0000 Subject: [PATCH 008/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 3e9e7d3edd7789dafd8cc20884f672b3bf3eaa7d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 16:00:40 +0000 Subject: [PATCH 009/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ba40cd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCj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AAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3d7a2ce..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From dcebda886d25ecb5b9c4925c70bee1b5ae371d1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 16:03:45 +0000 Subject: [PATCH 010/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 ---- ctor/benchmark/benchmark.js | 145 -- ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 ---- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----------- ctor/test/test.validate.js | 294 --- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 2717 insertions(+), 7121 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 a85636e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T00:37:05.521Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index 97f777d..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var CLI = require( './main.js' ); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 060fdcd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import cli = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - cli; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5ba40cd --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFl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wF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..85b9973 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 398214d752fa4b2b999313c80f5d00d0e0b8c8ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 01:02:16 +0000 Subject: [PATCH 011/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From fb2b3f39dcc097adb7614cd21993f6ec85d33f9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:28:44 +0000 Subject: [PATCH 012/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ba40cd..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar CLI = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,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GAA0B,IAArB2E,UAAUnC,OAAf,CAIA,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGI,GAAUL,GAAMC,QANfI,GAAUL,GAAM,MAoClBoE,GAAaK,GAAI/F,UAAW,SAAS,SAAkB4G,EAAOrF,GAC7D,IAAIuF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 85b9973..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 08286a7f89a03223bb1c05576b1e5099f833241e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:31:38 +0000 Subject: [PATCH 013/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 ---- ctor/benchmark/benchmark.js | 145 -- ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 ---- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----------- ctor/test/test.validate.js | 294 --- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 2717 insertions(+), 7121 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 4db103a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:01:04.691Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 060fdcd..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import cli = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - cli; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..acd030a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ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AQD,IAE7BD,EADA8C,EAAI7D,EAAMgB,IACD1B,EAAOuE,GAEjB,OAAO9C,EAaR,SAASnD,EAAMa,GACd6D,GAAIwB,MAAOvG,EAAKK,MAChBsF,EAAKa,MAAOtF,GAAQ,GAYrB,SAASZ,IACRyE,GAAIwB,MAAOvG,EAAKM,SAChBqF,EAAKa,SAoBPnB,GAAaK,GAAI/F,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArB2E,UAAUnC,OAAf,CAIA,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGI,GAAUL,GAAMC,QANfI,GAAUL,GAAM,MAoClBoE,GAAaK,GAAI/F,UAAW,SAAS,SAAkB4G,EAAOrF,GAC7D,IAAIuF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..733a4ff --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 8915f45546c59b9987a96a2ea4afa12169e0c294 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 11 Oct 2022 22:00:13 +0000 Subject: [PATCH 014/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 25968d218c846b6564cb3ea4e5e5569a76f4cb69 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 11 Oct 2022 22:35:12 +0000 Subject: [PATCH 015/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index acd030a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,KAAOJ,EAAQI,KACM,iBAAdL,EAAKK,MACT,IAAIH,UAAWX,EAAQ,8DAA+D,OAAQS,EAAKK,OAGvGZ,EAAWU,KAAMF,EAAS,aAC9BD,EAAKM,QAAUL,EAAQK,QACM,iBAAjBN,EAAKM,SACT,IAAIJ,UAAWX,EAAQ,8DAA+D,UAAWS,EAAKM,UAG1Gb,EAAWU,KAAMF,EAAS,WAC9BD,EAAKO,MAAQN,EAAQM,MACM,iBAAfP,EAAKO,OAA4C,kBAAfP,EAAKO,OAC3C,IAAIL,UAAWX,EAAQ,0FAA2F,QAASS,EAAKO,QAGpId,EAAWU,KAAMF,EAAS,aAC9BD,EAAKQ,QAAUP,EAAQO,QACM,kBAA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F2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 733a4ff..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 34f133e36bf2f1db81614a60de7bdf9e8542842c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 11 Oct 2022 22:37:47 +0000 Subject: [PATCH 016/165] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 41 +- branches.md | 53 - ctor/README.md | 454 ---- ctor/benchmark/benchmark.js | 145 -- ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 ---- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----------- ctor/test/test.validate.js | 294 --- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 40 - 57 files changed, 2717 insertions(+), 7120 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..acd030a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,KAAOJ,EAAQI,KACM,iBAAdL,EAAKK,MACT,IAAIH,UAAWX,EAAQ,8DAA+D,OAAQS,EAAKK,OAGvGZ,EAAWU,KAAMF,EAAS,aAC9BD,EAAKM,QAAUL,EAAQK,QACM,iBAAjBN,EAAKM,SACT,IAAIJ,UAAWX,EAAQ,8DAA+D,UAAWS,EAAKM,UAG1Gb,EAAWU,KAAMF,EAAS,WAC9BD,EAAKO,MAAQN,EAAQM,MACM,iBAAfP,EAAKO,OAA4C,kBAAfP,EAAK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AKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..504db63 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 02db9c13d0262025686b2d852d28b29e7684d1b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:00:38 +0000 Subject: [PATCH 017/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 3030d71f5cdc47ebd3bab9910085ef46f3363fba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:21:38 +0000 Subject: [PATCH 018/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2738 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index acd030a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,IAI7D,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,6EC1MtE,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,GCjB1BQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,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AAO9C,EAaR,SAASnD,EAAMa,GACd6D,GAAIwB,MAAOvG,EAAKK,MAChBsF,EAAKa,MAAOtF,GAAQ,GAYrB,SAASZ,IACRyE,GAAIwB,MAAOvG,EAAKM,SAChBqF,EAAKa,SAoBPnB,GAAaK,GAAI/F,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArB2E,UAAUnC,OAAf,CAIA,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGI,GAAUL,GAAMC,QANfI,GAAUL,GAAM,MAoClBoE,GAAaK,GAAI/F,UAAW,SAAS,SAAkB4G,EAAOrF,GAC7D,IAAIuF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,OAEJuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,MAmBjBpB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,MAMZ,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,GAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 504db63..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 835000edcb3f6583323ad619634a6505d9480647 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 13:24:21 +0000 Subject: [PATCH 019/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 --- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 --- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 -------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 4072 insertions(+), 7121 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 c940361..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:48:04.540Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..87dd5a0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAs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O,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,CACN,MACEuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,EACjB,IAkBApB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,EACZ,IAKA,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,CAAA,EAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..453ae8a --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 330a3e1720123c7d61b839ee4a5963a1eab5c90d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 23:26:07 +0000 Subject: [PATCH 020/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2843555..7043157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 49b26b56b3d53b20d802b2571f4348c66548806b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:20:56 +0000 Subject: [PATCH 021/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4093 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 87dd5a0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,4EC3MA,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,EClBIQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQ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ChXA0F,GDgXiBlB,GEjYjBmB,GAAA,CAAA,EAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 453ae8a..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 0157b204a13a1aa76480aa9c7799cde328d90dca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:23:47 +0000 Subject: [PATCH 022/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 --- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 --- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 -------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 4072 insertions(+), 7142 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 5145e80..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T20:51:28.431Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e6580b2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..87dd5a0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,4EC3MA,IAAAC,EARA,SAAoBL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,EClBIQ,EAASC,EAKTC,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAsFpB,IAAAE,EApDA,SAAmBC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWX,EAAQ,qEAAsEU,IAEhGR,EAAWU,KAAMF,EAAS,SAC9BD,EAAKI,IAAMH,EAAQG,IACM,iBAAbJ,EAAKI,KAAiC,OAAbJ,EAAKI,KAAgBP,EAASG,EAAKI,MAChE,IAAIF,UAAWX,EAAQ,+DAAgE,MAAOS,EAAKI,MAGvGX,EAAWU,KAAMF,EAAS,UAC9BD,EAAKK,KAAOJ,EAAQI,KACM,iBAAdL,EAAKK,MACT,IAAIH,UAAWX,EAAQ,8DAA+D,OAAQS,EAAKK,OAGvGZ,EAAWU,KAAMF,EAAS,aAC9BD,EAAKM,QAAUL,EAAQK,QACM,iBAAjBN,EAAKM,SACT,IAAIJ,UAAWX,EAAQ,8DAA+D,UAAWS,EAAKM,UAG1Gb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aK,GAAI/F,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArB2E,UAAUnC,OAAf,CAIA,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGI,GAAUL,GAAMC,EAJf,MAFAI,GAAUL,GAAM,EAOlB,IA6BAoE,GAAaK,GAAI/F,UAAW,SAAS,SAAkB4G,EAAOrF,GAC7D,IAAIuF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIxG,UAAWX,GAAQ,yEAA0EgH,IAExG,GAAKV,UAAUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,CACN,MACEuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,EACjB,IAkBApB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,EACZ,IAKA,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,CAAA,EAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7043157..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..55aec78 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From c0ba0d6f2dd701180a259ad90f381d12f639ab42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:09:13 +0000 Subject: [PATCH 023/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c262b4..8f374c6 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From e679d0a939fcd2fcb37bdae5a0c5cc6f45912e5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 16:10:47 +0000 Subject: [PATCH 024/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4093 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e6580b2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}};var l=function(e){return Math.floor(e)===e},u=t,p=Object.prototype.hasOwnProperty,f=Array.isArray;var c=function(e,t){return"object"!=typeof t||null===t||f(t)?new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t)):p.call(t,"pkg")&&(e.pkg=t.pkg,"object"!=typeof e.pkg||null===e.pkg||f(e.pkg))?new TypeError(u("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):p.call(t,"help")&&(e.help=t.help,"string"!=typeof e.help)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):p.call(t,"version")&&(e.version=t.version,"string"!=typeof e.version)?new TypeError(u("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):p.call(t,"title")&&(e.title=t.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(u("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):p.call(t,"updates")&&(e.updates=t.updates,"boolean"!=typeof e.updates)?new TypeError(u("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):p.call(t,"argv")&&(e.argv=t.argv,!f(e.argv))?new TypeError(u("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):p.call(t,"options")&&(e.options=t.options,"object"!=typeof e.options||null===e.options||f(e.options))?new TypeError(u("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null},v="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function g(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}var d=g,m=h;function b(e){if(d===setTimeout)return setTimeout(e,0);if((d===g||!d)&&setTimeout)return d=setTimeout,setTimeout(e,0);try{return d(e,0)}catch(t){try{return d.call(null,e,0)}catch(t){return d.call(this,e,0)}}}"function"==typeof v.setTimeout&&(d=setTimeout),"function"==typeof v.clearTimeout&&(m=clearTimeout);var y,w=[],k=!1,j=-1;function T(){k&&y&&(k=!1,y.length?w=y.concat(w):j=-1,w.length&&E())}function E(){if(!k){var e=b(T);k=!0;for(var t=w.length;t;){for(y=w,w=[];++j1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))},ee=r;function te(){return this instanceof te?this:new te}n(te.prototype,"notify",ee);var ne=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof t||!ie(t)||t<0)throw new TypeError(re("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",t));n=t}else n=1;le.error("Error: %s",e.message),ue(ae,n)})),ve(ge.prototype,"exit",(function(e){if(0===arguments.length)return ae.exit(0);if("number"!=typeof e||!ie(e)||e<0)throw new TypeError(re("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ae.exit(e)}));var he=ge,de={};e(de,"CLI",he);export{he as CLI,de as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 87dd5a0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../ctor/lib/index.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property' ;\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","is_integer","Math","floor","format","require$$0","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate_1","opts","options","TypeError","call","pkg","help","version","title","updates","argv","process","console_1","console","NODE_VERSION","versions","node","exit_code","proc","code","v","split","parseInt","exitCode","setTimeout","exit","noop","require$$1","Notifier","this","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","require$$2","isInteger","require$$3","validate","require$$4","require$$5","log","require$$6","require$$7","notifier","defineProperty","objectKeys","setReadOnly","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notify","k","error","close","c","Error","message","lib","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA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AUnC,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,gFAAiF2B,IAE/GuF,EAAIvF,CACN,MACEuF,EAAI,EAEL1B,GAAIwB,MAAO,YAAaA,EAAMI,SAC9BrF,GAAUL,GAAMwF,EACjB,IAkBApB,GAAaK,GAAI/F,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB2E,UAAUnC,OACd,OAAOzC,GAAKO,KAAM,GAEnB,GAAqB,iBAATN,IAAsBwD,GAAWxD,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWX,GAAQ,qEAAsE2B,IAEpGD,GAAKO,KAAMN,EACZ,IAKA,IChXA0F,GDgXiBlB,GEjYjBmB,GAAA,CAAA,EAUAxB,EAAAwB,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 55aec78..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 49b4256b9d07385a70159d00f7baa390efa23ca6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 16:13:46 +0000 Subject: [PATCH 025/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 --- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 --- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 -------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 4072 insertions(+), 7147 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 eb77786..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:42:57.046Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5a5e17a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function x(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&_())}function _(){if(!E){var e=k(x);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..079ef51 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6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,GAA0B,IAArB+D,UAAUxB,OACd,OAAO9C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAA+E,GAAA,CAAA,EAUAvE,EAAAuE,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 8f374c6..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7cd6cfa --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From a2c279763d10c08998e40acca140c04d9d04df41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:32:06 +0000 Subject: [PATCH 026/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4c4da87..f7263f1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 56c81dc86fd1f09fa791f140eb9a6f1231322ac4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 06:41:10 +0000 Subject: [PATCH 027/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4093 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5a5e17a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function x(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&_())}function _(){if(!E){var e=k(x);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 079ef51..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,gCCnNA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC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6cfa..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 04bc736a140e71364a742053bd6924fb11f48b93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 06:44:06 +0000 Subject: [PATCH 028/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 --- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 -- ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 --- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 -------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 4072 insertions(+), 7158 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 34fc4bd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:36:50.888Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2118c8e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function x(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&_())}function _(){if(!E){var e=k(x);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..079ef51 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,gCCnNA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,E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ADAoC,EAAInD,EAAMgB,IACD1B,EAAO6D,GAEjB,OAAOpC,CACP,CAYD,SAASjD,EAAMY,GACdN,GAAIgF,MAAO5F,EAAKM,MAChByE,EAAKc,MAAO3E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIgF,MAAO5F,EAAKO,SAChBwE,EAAKc,OACL,CACF,CAkBAnE,GAAaoD,GAAInF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArB+D,UAAUxB,OAAf,CAIA,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAaoD,GAAInF,UAAW,SAAS,SAAkBiG,EAAO1E,GAC7D,IAAI4E,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAI7F,UAAWC,EAAQ,yEAA0EyF,IAExG,GAAKX,UAAUxB,OAAS,EAAI,CAC3B,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/G4E,EAAI5E,CACN,MACE4E,EAAI,EAELlF,GAAIgF,MAAO,YAAaA,EAAMI,SAC9B/E,GAAUN,EAAMmF,EACjB,IAkBApE,GAAaoD,GAAInF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB+D,UAAUxB,OACd,OAAO9C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAA+E,GAAA,CAAA,EAUAvE,EAAAuE,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index f7263f1..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5ad8609 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 808775d36f7a8bcf7b001b79738477647b2bc1c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:21:15 +0000 Subject: [PATCH 029/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4c4da87..f7263f1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert", @@ -79,4 +80,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From ecf57c0daf414da153833d356a4e37dde7ec407b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:11:41 +0000 Subject: [PATCH 030/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4093 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2118c8e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function x(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&_())}function _(){if(!E){var e=k(x);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 079ef51..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;uuBA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,gCCnNA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ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IAArB+D,UAAUxB,OAAf,CAIA,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAaoD,GAAInF,UAAW,SAAS,SAAkBiG,EAAO1E,GAC7D,IAAI4E,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAI7F,UAAWC,EAAQ,yEAA0EyF,IAExG,GAAKX,UAAUxB,OAAS,EAAI,CAC3B,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/G4E,EAAI5E,CACN,MACE4E,EAAI,EAELlF,GAAIgF,MAAO,YAAaA,EAAMI,SAC9B/E,GAAUN,EAAMmF,EACjB,IAkBApE,GAAaoD,GAAInF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB+D,UAAUxB,OACd,OAAO9C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAA+E,GAAA,CAAA,EAUAvE,EAAAuE,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ad8609..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 23f17d7f1d6195ce9c8db114643267ed1dbafe55 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:14:39 +0000 Subject: [PATCH 031/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7158 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 d77e05e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:41:46.279Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index 071b42e..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/cli" -click B href "https://github.com/stdlib-js/cli/tree/main" -click C href "https://github.com/stdlib-js/cli/tree/production" -click D href "https://github.com/stdlib-js/cli/tree/esm" -click E href "https://github.com/stdlib-js/cli/tree/deno" -click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bb7d2c7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8fb041f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;22BA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,gCCnNA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ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IAArB+D,UAAUxB,OAAf,CAIA,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAaoD,GAAInF,UAAW,SAAS,SAAkBiG,EAAO1E,GAC7D,IAAI4E,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAI7F,UAAWC,EAAQ,yEAA0EyF,IAExG,GAAKX,UAAUxB,OAAS,EAAI,CAC3B,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/G4E,EAAI5E,CACN,MACE4E,EAAI,EAELlF,GAAIgF,MAAO,YAAaA,EAAMI,SAC9B/E,GAAUN,EAAMmF,EACjB,IAkBApE,GAAaoD,GAAInF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB+D,UAAUxB,OACd,OAAO9C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAA+E,GAAA,CAAA,EAUAvE,EAAAuE,GAAA,MAAAnB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index f7263f1..4dadc68 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert", - "@stdlib/bench": "github:stdlib-js/bench", - "@stdlib/fs": "github:stdlib-js/fs", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d139b2e --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 385eb1af9981c29fc8876783e45658f8387fbd60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 01:08:20 +0000 Subject: [PATCH 032/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f0e391fce4af1da09bf77b4eecb7c14bfe6c6847 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:35:28 +0000 Subject: [PATCH 033/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bb7d2c7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.13-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&(n.strings[r[e]]=!0)}));var o=t.default||{},a={_:[]};Object.keys(n.bools).forEach((function(e){u(e,void 0!==o[e]&&o[e])}));var l=[];function u(e,t,o){if(!o||!n.unknownFn||function(e,t){return n.allBools&&/^--[^=]+$/.test(t)||n.strings[e]||n.bools[e]||r[e]}(e,o)||!1!==n.unknownFn(o)){var s=!n.strings[e]&&i(t)?Number(t):t;p(a,e.split("."),s),(r[e]||[]).forEach((function(e){p(a,e.split("."),s)}))}}function p(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8fb041f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["module.exports = function (args, opts) {\n if (!opts) opts = {};\n \n var flags = { bools : {}, strings : {}, unknownFn: null };\n\n if (typeof opts['unknown'] === 'function') {\n flags.unknownFn = opts['unknown'];\n }\n\n if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {\n flags.allBools = true;\n } else {\n [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {\n flags.bools[key] = true;\n });\n }\n \n var aliases = {};\n Object.keys(opts.alias || {}).forEach(function (key) {\n aliases[key] = [].concat(opts.alias[key]);\n aliases[key].forEach(function (x) {\n aliases[x] = [key].concat(aliases[key].filter(function (y) {\n return x !== y;\n }));\n });\n });\n\n [].concat(opts.string).filter(Boolean).forEach(function (key) {\n flags.strings[key] = true;\n if (aliases[key]) {\n flags.strings[aliases[key]] = true;\n }\n });\n\n var defaults = opts['default'] || {};\n \n var argv = { _ : [] };\n Object.keys(flags.bools).forEach(function (key) {\n setArg(key, defaults[key] === undefined ? false : defaults[key]);\n });\n \n var notFlags = [];\n\n if (args.indexOf('--') !== -1) {\n notFlags = args.slice(args.indexOf('--')+1);\n args = args.slice(0, args.indexOf('--'));\n }\n\n function argDefined(key, arg) {\n return (flags.allBools && /^--[^=]+$/.test(arg)) ||\n flags.strings[key] || flags.bools[key] || aliases[key];\n }\n\n function setArg (key, val, arg) {\n if (arg && flags.unknownFn && !argDefined(key, arg)) {\n if (flags.unknownFn(arg) === false) return;\n }\n\n var value = !flags.strings[key] && isNumber(val)\n ? Number(val) : val\n ;\n setKey(argv, key.split('.'), value);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), value);\n });\n }\n\n function setKey (obj, keys, value) {\n var o = obj;\n for (var i = 0; i < keys.length-1; i++) {\n var key = keys[i];\n if (isConstructorOrProto(o, key)) return;\n if (o[key] === undefined) o[key] = {};\n if (o[key] === Object.prototype || o[key] === Number.prototype\n || o[key] === String.prototype) o[key] = {};\n if (o[key] === Array.prototype) o[key] = [];\n o = o[key];\n }\n\n var key = keys[keys.length - 1];\n if (isConstructorOrProto(o, key)) return;\n if (o === Object.prototype || o === Number.prototype\n || o === String.prototype) o = {};\n if (o === Array.prototype) o = [];\n if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {\n o[key] = value;\n }\n else if (Array.isArray(o[key])) {\n o[key].push(value);\n }\n else {\n o[key] = [ o[key], value ];\n }\n }\n \n function aliasIsBoolean(key) {\n return aliases[key].some(function (x) {\n return flags.bools[x];\n });\n }\n\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n \n if (/^--.+=/.test(arg)) {\n // Using [\\s\\S] instead of . because js doesn't support the\n // 'dotall' regex modifier. See:\n // http://stackoverflow.com/a/1068308/13216\n var m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n var key = m[1];\n var value = m[2];\n if (flags.bools[key]) {\n value = value !== 'false';\n }\n setArg(key, value, arg);\n }\n else if (/^--no-.+/.test(arg)) {\n var key = arg.match(/^--no-(.+)/)[1];\n setArg(key, false, arg);\n }\n else if (/^--.+/.test(arg)) {\n var key = arg.match(/^--(.+)/)[1];\n var next = args[i + 1];\n if (next !== undefined && !/^-/.test(next)\n && !flags.bools[key]\n && !flags.allBools\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, next, arg);\n i++;\n }\n else if (/^(true|false)$/.test(next)) {\n setArg(key, next === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n else if (/^-[^-]+/.test(arg)) {\n var letters = arg.slice(1,-1).split('');\n \n var broken = false;\n for (var j = 0; j < letters.length; j++) {\n var next = arg.slice(j+2);\n \n if (next === '-') {\n setArg(letters[j], next, arg)\n continue;\n }\n \n if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {\n setArg(letters[j], next.split('=')[1], arg);\n broken = true;\n break;\n }\n \n if (/[A-Za-z]/.test(letters[j])\n && /-?\\d+(\\.\\d*)?(e-?\\d+)?$/.test(next)) {\n setArg(letters[j], next, arg);\n broken = true;\n break;\n }\n \n if (letters[j+1] && letters[j+1].match(/\\W/)) {\n setArg(letters[j], arg.slice(j+2), arg);\n broken = true;\n break;\n }\n else {\n setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n }\n }\n \n var key = arg.slice(-1)[0];\n if (!broken && key !== '-') {\n if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])\n && !flags.bools[key]\n && (aliases[key] ? !aliasIsBoolean(key) : true)) {\n setArg(key, args[i+1], arg);\n i++;\n }\n else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {\n setArg(key, args[i+1] === 'true', arg);\n i++;\n }\n else {\n setArg(key, flags.strings[key] ? '' : true, arg);\n }\n }\n }\n else {\n if (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n argv._.push(\n flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)\n );\n }\n if (opts.stopEarly) {\n argv._.push.apply(argv._, args.slice(i + 1));\n break;\n }\n }\n }\n \n Object.keys(defaults).forEach(function (key) {\n if (!hasKey(argv, key.split('.'))) {\n setKey(argv, key.split('.'), defaults[key]);\n \n (aliases[key] || []).forEach(function (x) {\n setKey(argv, x.split('.'), defaults[key]);\n });\n }\n });\n \n if (opts['--']) {\n argv['--'] = new Array();\n notFlags.forEach(function(key) {\n argv['--'].push(key);\n });\n }\n else {\n notFlags.forEach(function(key) {\n argv._.push(key);\n });\n }\n\n return argv;\n};\n\nfunction hasKey (obj, keys) {\n var o = obj;\n keys.slice(0,-1).forEach(function (key) {\n o = (o[key] || {});\n });\n\n var key = keys[keys.length - 1];\n return key in o;\n}\n\nfunction isNumber (x) {\n if (typeof x === 'number') return true;\n if (/^0x[0-9a-f]+$/i.test(x)) return true;\n return /^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/.test(x);\n}\n\n\nfunction isConstructorOrProto (obj, key) {\n return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';\n}\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","allBools","concat","filter","Boolean","forEach","aliases","keys","alias","y","string","defaults","_","setArg","undefined","notFlags","val","arg","argDefined","value","Number","setKey","o","i","length","String","push","aliasIsBoolean","some","indexOf","slice","m","match","next","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","k","error","close","c","Error","message","ns"],"mappings":";;22BA+OA,SAASA,EAAUC,GACf,MAAiB,iBAANA,MACP,iBAAiBC,KAAKD,IACnB,6CAA6CC,KAAKD,GAC7D,CAGA,SAASE,EAAsBC,EAAKC,GAChC,MAAe,gBAARA,GAA6C,mBAAbD,EAAIC,IAA+B,cAARA,CACtE,gCCnNA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC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AAaoD,GAAInF,UAAW,SAAS,SAAkBiG,EAAO1E,GAC7D,IAAI4E,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAI7F,UAAWC,EAAQ,yEAA0EyF,IAExG,GAAKX,UAAUxB,OAAS,EAAI,CAC3B,GAAqB,iBAATvC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/G4E,EAAI5E,CACN,MACE4E,EAAI,EAELlF,GAAIgF,MAAO,YAAaA,EAAMI,SAC9B/E,GAAUN,EAAMmF,EACjB,IAkBApE,GAAaoD,GAAInF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArB+D,UAAUxB,OACd,OAAO9C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAA+E,GAAA,CAAA,EAUAvE,EAAAuE,GAAA,MAAAnB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d139b2e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e8787a56ebb73fe1b03e4a4e82755e8d2ae5f55d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:38:36 +0000 Subject: [PATCH 034/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7293 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 ad41b1d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T00:51:51.303Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAK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AAKM,MAChB8E,EAAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f558012 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 41007f916624a92a83ef39b2436bd3daca7b1af7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 01:06:27 +0000 Subject: [PATCH 035/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 510c7114d99fa03505b40220b3f3993a3329e3f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:19:25 +0000 Subject: [PATCH 036/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAA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AAMY,GACdN,GAAIoF,MAAOhG,EAAKM,MAChB8E,EAAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f558012..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 73b66929af042b256f3ad03b0a7e04a0135d3932 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:22:33 +0000 Subject: [PATCH 037/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7299 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 d4a063e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T00:50:47.741Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC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AsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ff19b79 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From bae09e175b65f850dd4b7a4bf1201bb5fcd68313 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 01:06:06 +0000 Subject: [PATCH 038/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From bea1f28153e85a204891a372d43448dfed02b941 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:14:05 +0000 Subject: [PATCH 039/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,S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,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ff19b79..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2c582c661f81240cd7b8bf2612a2f02fc5641600 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:17:20 +0000 Subject: [PATCH 040/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7299 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 393ca47..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T00:50:00.674Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,I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,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..166a27a --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From c050d29fa3a62d486ab720422af7493c02e7cc1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 01:11:57 +0000 Subject: [PATCH 041/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5a10ce0ba3167a36ea43cccb8ae1cd1c568db82c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:33:35 +0000 Subject: [PATCH 042/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ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,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 166a27a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ba25f7b7a740f2fcebddcded60aff18135b32478 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:37:49 +0000 Subject: [PATCH 043/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7299 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 0ef699d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T00:56:56.249Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAA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SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56a799c --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From a1b96b33782808981fef325cad938adf4853b7f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 01:10:55 +0000 Subject: [PATCH 044/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c235d1510621295ef5bc5527fc54a0e201e275bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:21:33 +0000 Subject: [PATCH 045/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UA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GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 56a799c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 51d2bad3db32d4b47bc482c37c459403e10deeb7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:24:29 +0000 Subject: [PATCH 046/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7299 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 c1544f3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T00:56:05.309Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAE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Y,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..88b4e59 --- /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 71f6e0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 1483e11f25a69346888bd53f0b360f0a865970b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 16:57:41 +0000 Subject: [PATCH 047/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From da8f79114538f9ab47c1b486e994a1ec0a3a4044 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 17:37:58 +0000 Subject: [PATCH 048/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACr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C,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 88b4e59..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 878e6a65961e5ba0489b66707ba8a8f2eb809fda Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 17:41:42 +0000 Subject: [PATCH 049/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 57 files changed, 6205 insertions(+), 7298 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","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,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..66f2bbc --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From dfb932bdccbf51faadb1d37b4359f1a80a723482 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 01:10:13 +0000 Subject: [PATCH 050/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ada583bed31627911d2c32fdde0ea4329df1a37d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:37:53 +0000 Subject: [PATCH 051/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","st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,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 66f2bbc..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 14bae5ec24142618f00e2a82b436122d1fd7a094 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:41:19 +0000 Subject: [PATCH 052/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 58 files changed, 6205 insertions(+), 7299 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 5c17df9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T00:53:07.918Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index 4fb7792..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IA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EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..81f1ff6 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From eed88693c657e5d7b47e844cf05103faff0c9561 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 14:01:11 +0000 Subject: [PATCH 053/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..82f6e7e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 554b9e360a0afd37be5a771a3e4133fe28c9d137 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 14:05:03 +0000 Subject: [PATCH 054/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 5a95514..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAA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qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 81f1ff6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ab4e3129f803c93afc1e723f8074d54453bc8415 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 14:08:13 +0000 Subject: [PATCH 055/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 6205 insertions(+), 7314 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 a9cc3c7..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 f4edd21..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: '56 20 * * 3' - - # 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 + + ```
@@ -111,7 +110,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,CAAQ,CAAE,EAE1GJ,EAAW,KAAMI,EAAS,KAAM,IACpCD,EAAK,IAAMC,EAAQ,IACd,OAAOD,EAAK,KAAQ,UAAYA,EAAK,MAAQ,MAAQF,EAASE,EAAK,GAAI,GACpE,IAAI,UAAWJ,EAAQ,+DAAgE,MAAOI,EAAK,GAAI,CAAE,EAG7GH,EAAW,KAAMI,EAAS,MAAO,IACrCD,EAAK,KAAOC,EAAQ,KACf,OAAOD,EAAK,MAAS,UAClB,IAAI,UAAWJ,EAAQ,8DAA+D,OAAQI,EAAK,IAAK,CAAE,EAG9GH,EAAW,KAAMI,EAAS,SAAU,IACxCD,EAAK,QAAUC,EAAQ,QAClB,OAAOD,EAAK,SAAY,UACrB,IAAI,UAAWJ,EAAQ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AAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..da654a7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c837643 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ,0FAA2F,QAASH,EAAKQ,QAGpIf,EAAWW,KAAMH,EAAS,aAC9BD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EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 82f6e7e..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c42b54c --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From aec28eaa80a8d726f7c32470cc9785febc75feb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 01:21:01 +0000 Subject: [PATCH 056/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..cc75ce9 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From afba7da848226d360ebbc421e3b626faefa918c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 08:12:43 +0000 Subject: [PATCH 057/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 1a5af75..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da654a7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.0.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.0.14-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c837643..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;22BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ,0FAA2F,QAASH,EAAKQ,QAGpIf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3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c42b54c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9ffe466b45a0bcf55f97efba72f558ea784a1e32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 08:15:51 +0000 Subject: [PATCH 058/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 40 - test/test.js | 40 - 63 files changed, 6205 insertions(+), 7448 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 5e99f1d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T00:49:34.459Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,CAAQ,CAAE,EAE1GJ,EAAW,KAAMI,EAAS,KAAM,IACpCD,EAAK,IAAMC,EAAQ,IACd,OAAOD,EAAK,KAAQ,UAAYA,EAAK,MAAQ,MAAQF,EAASE,EAAK,GAAI,GACpE,IAAI,UAAWJ,EAAQ,+DAAgE,MAAOI,EAAK,GAAI,CAAE,EAG7GH,EAAW,KAAMI,EAAS,MAAO,IACrCD,EAAK,KAAOC,EAAQ,KACf,OAAOD,EAAK,MAAS,UAClB,IAAI,UAAWJ,EAAQ,8DAA+D,OAAQI,EAAK,IAAK,CAAE,EAG9GH,EAAW,KAAMI,EAAS,SAAU,IACxCD,EAAK,QA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AAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9990879 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.0-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OA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,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index cc75ce9..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e809545 --- /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 24c7167..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 6d3e1242c47c3d0590083c9b29321fa0e24ad756 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 03:21:23 +0000 Subject: [PATCH 059/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..bc5c93b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f8bb3442660c14805927f7445f037b0e22379668 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 08:32:15 +0000 Subject: [PATCH 060/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 1a5af75..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9990879..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.0-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAI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,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e809545..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 81536299831652e1ad64278b03abca0fb201d147 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 08:36:58 +0000 Subject: [PATCH 061/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 40 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7447 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAA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,EAAM2B,CAAK,CACtB,CAAC,EA6BDrB,EAAaI,EAAI,UAAW,QAAS,SAAkBkB,EAAOD,EAAO,CACpE,IAAIE,EACJ,GAAK,EAAGD,aAAiB,OACxB,MAAM,IAAI,UAAWhC,EAAQ,yEAA0EgC,CAAM,CAAE,EAEhH,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAo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dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index bc5c93b..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d2a4639 --- /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 24c7167..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ba08086833ccd85e2a07b72309598dc0e8555ce6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 01:19:21 +0000 Subject: [PATCH 062/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..bc5c93b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 07b7b682c27b97eb4b869184d547537e9959ef34 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 07:49:24 +0000 Subject: [PATCH 063/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 1a5af75..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,K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AW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d2a4639..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d03d3c5b97b3ada819028e69acc069fc56598403 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 07:51:56 +0000 Subject: [PATCH 064/165] 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 | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 63 files changed, 6205 insertions(+), 7449 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 2a9240a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T00:48:40.244Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,CAAQ,CAAE,EAE1GJ,EAAW,KAAMI,EAAS,KAAM,IACpCD,EAAK,IAAMC,EAAQ,IACd,OAAOD,EAAK,KAAQ,UAAYA,EAAK,MAAQ,MAAQF,EAASE,EAAK,GAAI,GACpE,IAAI,UAAWJ,EAAQ,+DAAgE,MAAOI,EAAK,GAAI,CAAE,EAG7GH,EAAW,KAAMI,EAAS,MAAO,IACrCD,EAAK,KAAOC,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B,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UA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AFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index bc5c93b..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..10432a7 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 66a2eb4b70eb80ed2bf1b04c82b2eca19f0ced40 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 20:51:04 +0000 Subject: [PATCH 065/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60f1fd2..bc5c93b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1d4af4dcb4cca06d24ccc0e0e8fba6ed18ad1c19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 23:02:55 +0000 Subject: [PATCH 066/165] Remove files --- index.d.ts | 44 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6226 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 1a5af75..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/* tslint:disable:max-line-length */ -/* tslint:disable:max-file-line-count */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,O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AML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 10432a7..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 258fcd66cc238e3e1cb83a7a88f200d5b87b7fca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 23:05:14 +0000 Subject: [PATCH 067/165] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7448 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7C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,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3GzB,EAAUF,EAAM2B,CAAK,CACtB,CAAC,EA6BDrB,EAAaI,EAAI,UAAW,QAAS,SAAkBkB,EAAOD,EAAO,CACpE,IAAIE,EACJ,GAAK,EAAGD,aAAiB,OACxB,MAAM,IAAI,UAAWhC,EAAQ,yEAA0EgC,CAAM,CAAE,EAEhH,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,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.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index bc5c93b..ed1b6be 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.0.10", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d73b09d --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 6d7204650806a387624e3c43bd187bc8aa6171e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 03:27:48 +0000 Subject: [PATCH 068/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 684ae35..91d7ba9 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 7413530b73a5ea91afdfdf9e4418ac713453b629 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 04:13:33 +0000 Subject: [PATCH 069/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C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AQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d73b09d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6391b5f85d7eb581230a60f3739b0f0b4bd64df6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 04:15:58 +0000 Subject: [PATCH 070/165] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7448 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,CAAQ,CAAE,EAE1GJ,EAAW,KAAMI,EAAS,KAAM,IACpCD,EAAK,IAAMC,EAAQ,IACd,OAAOD,EAAK,KAAQ,UAAYA,EAAK,MAAQ,MAAQF,EAASE,EAAK,GAAI,GACpE,IAAI,UAAWJ,EAAQ,+DAAgE,MAAOI,EAAK,GAAI,CAAE,EAG7GH,EAAW,KAAMI,EAAS,MAAO,IACrCD,EAAK,KAAOC,EAAQ,KACf,OAAOD,EAAK,MAAS,UAClB,IAAI,UAAWJ,EAAQ,8DAA+D,OAAQI,EAAK,IAAK,CAAE,EAG9GH,EAAW,KAAMI,EAAS,SAAU,IACxCD,EAAK,QAAUC,EAAQ,QAClB,OAAOD,EAAK,SAAY,UACrB,IAAI,UAAWJ,EAAQ,8DAA+D,UAAWI,EAAK,OAAQ,CAAE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,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ,0FAA2F,QAASH,EAAKQ,QAGpIf,EAAWW,KAAMH,EAAS,aAC9BD,EAAKS,QA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AUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 91d7ba9..26ca5bf 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.0", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6495a58 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 27df0112acf6ce4bb0b93d2880c1888f894c4710 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 04:19:00 +0000 Subject: [PATCH 071/165] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 93b6087..f04f5ac 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.1.0-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From ce0bce4b0dd4ba2a9bef34cc4dfd172bd68c9bda Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 04:57:50 +0000 Subject: [PATCH 075/165] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- branches.md | 53 - ctor/README.md | 454 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7448 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index e041e71..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,454 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,I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AAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+C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ACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4838635 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ea73c68b8541a7fff7c4b2c9ef0430865daeed2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Nov 2023 05:11:36 +0000 Subject: [PATCH 076/165] Update README.md for ESM bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index caa2f31..d338ddd 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.1.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.1.1-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From f500d631621c29f3242a52d934772a15c8261b80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 05:20:03 +0000 Subject: [PATCH 080/165] 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 | 207 - .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 | 41 +- branches.md | 53 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7402 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index 10e1a1d..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC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qEAAsE+B,CAAK,CAAE,EAE3GzB,EAAUF,EAAM2B,CAAK,CACtB,CAAC,EA6BDrB,EAAaI,EAAI,UAAW,QAAS,SAAkBkB,EAAOD,EAAO,CACpE,IAAIE,EACJ,GAAK,EAAGD,aAAiB,OACxB,MAAM,IAAI,UAAWhC,EAAQ,yEAA0EgC,CAAM,CAAE,EAEhH,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1cdbcd0..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-unused-expression */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EA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mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..949d19b --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 47f2d63ed0790fea20f03560add69e647af22b02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 21:44:27 +0000 Subject: [PATCH 081/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9b496df..72b5aac 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From cb14369f29d7692c0b5fb53e2e609ab9b47b00d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 22:35:00 +0000 Subject: [PATCH 082/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ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GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 949d19b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9c47c7c99634a83fb34cacd078525c6dbeb89659 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 22:39:15 +0000 Subject: [PATCH 083/165] 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 | 207 - .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 | 41 +- branches.md | 53 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 62 files changed, 6205 insertions(+), 7402 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\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AK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ,0FAA2F,QAASH,EAAKQ,QAGpIf,EAAWW,KAAMH,EAAS,aAC9BD,EAAKS,QAAUR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,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cb24836 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From bc0c139006124c7ba560fcf7cdf9d96b416e61de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 01:17:49 +0000 Subject: [PATCH 084/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9b496df..72b5aac 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5942ab5866ebbbc5d76a15de92f5bd574fbdda23 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 04:50:23 +0000 Subject: [PATCH 085/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,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KM,MAChB8E,EAAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cb24836..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f0740b787425568b6fb2fad3c67c4f673649ed90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 04:52:57 +0000 Subject: [PATCH 086/165] 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 | 207 - .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 | 41 +- branches.md | 53 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 63 files changed, 6205 insertions(+), 7398 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 239bc44..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T00:52:05.537Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ef77ab1..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. diff --git a/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY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,MAAM,IAAI,UAAWhC,EAAQ,yEAA0EgC,CAAM,CAAE,EAEhH,GAAK,UAAU,OAAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5f9724 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI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,GAAIoF,MAAOhG,EAAKM,MAChB8E,EAAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e8f8a52 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From b3d0e89fd3a7750d6143ab344a8d14506a2677ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 01:10:36 +0000 Subject: [PATCH 087/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9b496df..72b5aac 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 73ac3fba5f4da058160831d2040662e87bdc9576 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 03:01:00 +0000 Subject: [PATCH 088/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e5f9724..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC3C,IAAIN,UAAWC,EAAQ,0FAA2F,QAASH,EAAKQ,QAGpIf,EAAWW,KAAMH,EAAS,aAC9BD,EAAKS,QAAUR,EAAQQ,QACM,kBAAjBT,EAAKS,SACT,IAAIP,UAAWC,EAAQ,+DAAgE,UAAWH,EAAKS,UA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EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e8f8a52..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e58209ad102b2aa45b34ed3cab5815252304202a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 03:03:42 +0000 Subject: [PATCH 089/165] 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 | 207 - .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 | 41 +- SECURITY.md | 5 - branches.md | 53 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 64 files changed, 6205 insertions(+), 7404 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 51e9b3c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T00:49:26.238Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 afa39bf..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: '56 20 * * 3' - - # 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 + + ```
@@ -122,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index faaa950..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[esm-url]: https://github.com/stdlib-js/cli/tree/esm \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,CAAQ,CAAE,EAE1GJ,EAAW,KAAMI,EAAS,KAAM,IACpCD,EAAK,IAAMC,EAAQ,IACd,OAAOD,EAAK,KAAQ,UAAYA,EAAK,MAAQ,MAAQF,EAASE,EAAK,GAAI,GACpE,IAAI,UAAWJ,EAAQ,+DAAgE,MAAOI,EAAK,GAAI,CAAE,EAG7GH,EAAW,KAAMI,EAAS,MAAO,IACrCD,EAAK,KAAOC,EAAQ,KACf,OAAOD,EAAK,MAAS,UAClB,IAAI,UAAWJ,EAAQ,8DAA+D,OAAQI,EAAK,IAAK,CAAE,EAG9GH,EAAW,KAAMI,EAAS,SAAU,IACxCD,EAAK,QAAUC,EAAQ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K,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5328a3f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,OAAQH,EAAKM,OAGvGb,EAAWW,KAAMH,EAAS,aAC9BD,EAAKO,QAAUN,EAAQM,QACM,iBAAjBP,EAAKO,SACT,IAAIL,UAAWC,EAAQ,8DAA+D,UAAWH,EAAKO,UAG1Gd,EAAWW,KAAMH,EAAS,WAC9BD,EAAKQ,MAAQP,EAAQO,MACM,iBAAfR,EAAKQ,OAA4C,kBAAfR,EAAKQ,OAC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EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ecc1f78 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ae945ac91b0fbd921ab5b9417b6a7ae3fe9865bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 01:09:21 +0000 Subject: [PATCH 090/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9b496df..72b5aac 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From b5acee1f32c4f78d61e46d1d5d0570d5ba322c8c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 02:42:44 +0000 Subject: [PATCH 091/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5328a3f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAI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BD,EADAN,EAAIJ,EAAMW,IACDzB,EAAOkB,GAEjB,OAAOM,CACP,CAYD,SAAShD,EAAMY,GACdN,GAAIoF,MAAOhG,EAAKM,MAChB8E,EAAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecc1f78..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ebe9a3a8a24b0da80e6ed88b247c9134ea6cdae6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 02:45:37 +0000 Subject: [PATCH 092/165] 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 | 207 - .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 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 64 files changed, 6205 insertions(+), 7409 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 e42d60e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T00:50:42.598Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 afa39bf..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,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AO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5328a3f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBA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,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 72b5aac..b219223 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.1.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1c72e84 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ac2031b2fec98404d3de16be20a760810d4b680e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 03:06:16 +0000 Subject: [PATCH 093/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 938fa3a..ccd780d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d3acdcd919fcef122c3a2ba06aae4c4157aae061 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 03:20:53 +0000 Subject: [PATCH 094/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5328a3f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IAAIH,UAAWC,EAAQ,+DAAgE,MAAOH,EAAKK,MAGvGZ,EAAWW,KAAMH,EAAS,UAC9BD,EAAKM,KAAOL,EAAQK,KACM,iBAAdN,EAAKM,MACT,IAAIJ,UAAWC,EAAQ,8DAA+D,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C,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1c72e84..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8d56ecfe89d00b8e759016aa1191c1af6e104a39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 03:23:39 +0000 Subject: [PATCH 095/165] 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 | 207 - .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 | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 63 files changed, 6205 insertions(+), 7412 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8f40da5..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,C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AAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5328a3f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,IA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,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index ccd780d..c561c8a 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.0", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e48ae11 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 78aee8bd8282876a50a1529ff7909217e964b1f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 03:34:59 +0000 Subject: [PATCH 096/165] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9734dce..cbc857f 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.2.0-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From a5753d5c863cc6a727c3b6632d8da34305e269d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 04:42:32 +0000 Subject: [PATCH 100/165] 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 | 207 - .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 | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - dist/index.d.ts | 3 - dist/index.js | 21 - dist/index.js.map | 7 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 40 - 63 files changed, 6205 insertions(+), 7412 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8f40da5..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 15e948f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ns from '../docs/types/index'; -export = ns; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f53c140..0000000 --- a/dist/index.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var j=a(function(fe,W){W.exports={pkg:{},help:"",title:!0,version:"",updates:!0,argv:null,options:{}}});var C=a(function(ge,I){ -function X(r){return Math.floor(r)===r}I.exports=X -});var A=a(function(ye,V){ -var s=require('@stdlib/string/format/dist'),u=Object.prototype.hasOwnProperty,c=Array.isArray;function Y(r,e){return typeof e!="object"||e===null||c(e)?new TypeError(s('0GZ2V',e)):u.call(e,"pkg")&&(r.pkg=e.pkg,typeof r.pkg!="object"||r.pkg===null||c(r.pkg))?new TypeError(s('0GZCd',"pkg",r.pkg)):u.call(e,"help")&&(r.help=e.help,typeof r.help!="string")?new TypeError(s('0GZ2W',"help",r.help)):u.call(e,"version")&&(r.version=e.version,typeof r.version!="string")?new TypeError(s('0GZ2W',"version",r.version)):u.call(e,"title")&&(r.title=e.title,typeof r.title!="string"&&typeof r.title!="boolean")?new TypeError(s("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",r.title)):u.call(e,"updates")&&(r.updates=e.updates,typeof r.updates!="boolean")?new TypeError(s('0GZ2o',"updates",r.updates)):u.call(e,"argv")&&(r.argv=e.argv,!c(r.argv))?new TypeError(s('0GZ8Z',"argv",r.argv)):u.call(e,"options")&&(r.options=e.options,typeof r.options!="object"||r.options===null||c(r.options))?new TypeError(s("invalid option. `%s` option must be a plain object. Option: `%s`.","options",r.options)):null;}V.exports=Y -});var x=a(function(ce,M){ -var Z=require("process");M.exports=Z -});var R=a(function(he,P){ -P.exports=console -});var _=a(function(me,N){ -var $=x(),ee=$.versions.node,re=10;function te(r,e){var i;if(i=ee.split("."),i[0]=parseInt(i[0],10),i[1]=parseInt(i[1],10),i[0]>0){r.exitCode=e;return}if(i[1]>10){r.exitCode=e;return}r.exitCode=e,setTimeout(o,re);function o(){r.exit(e)}}N.exports=te -});var L=a(function(be,F){ -var ie=require('@stdlib/utils/define-nonenumerable-read-only-property/dist'),ne=require('@stdlib/utils/noop/dist');function h(){return this instanceof h?this:new h}ie(h.prototype,"notify",ne);F.exports=h -});var K=a(function(ke,D){ -var ae=require("minimist"),m=require('@stdlib/string/format/dist'),f=j(),q=C(),oe=A(),n=x(),O=R(),E=_(),se=L(),ue=Object.defineProperty,S=Object.keys;function l(r,e,i){ue(r,e,{configurable:!1,enumerable:!1,writable:!1,value:i})}function p(r){var e,i,o,t,g,T,b,k;if(!(this instanceof p))return arguments.length?new p(r):new p;if(t={pkg:{},help:f.help,title:f.title,version:f.version,updates:f.updates,argv:f.argv,options:{}},arguments.length&&(k=oe(t,r),k))throw k;if(b=this,n.stdout.on("error",n.exit),n.stderr.on("error",n.exit),l(this,"args",G),l(this,"flags",H),l(this,"help",J),l(this,"version",Q),t.title===!0&&t.pkg?typeof t.pkg.bin=="object"&&t.pkg.bin!==null?(o=S(t.pkg.bin),n.title=o[0]):t.pkg.name&&(n.title=t.pkg.name):t.title&&(n.title=t.title),t.updates&&t.pkg&&t.pkg.name&&t.pkg.version&&(e={pkg:t.pkg},se(e).notify()),!t.version&&t.pkg&&t.pkg.version&&(t.version=t.pkg.version),t.argv?t.argv=t.argv.slice(2):t.argv=n.argv.slice(2),g=ae(t.argv,t.options),T=g._,delete g._,i=g,i.help)return this.help(0);if(i.version)return this.version();return this;function G(){return T.slice()}function H(){var v,d,w,y;for(v=S(i),d={},y=0;y1){if(typeof i!="number"||!q(i)||i<0)throw new TypeError(m('0GZ3X',i));o=i}else o=1;O.error("Error: %s",e.message),E(n,o)});l(p.prototype,"exit",function(e){if(arguments.length===0)return n.exit(0);if(typeof e!="number"||!q(e)||e<0)throw new TypeError(m('0GZ2K',e));n.exit(e)});D.exports=p -});var z=a(function(de,U){ -var le=K();U.exports=le -});var pe=require('@stdlib/utils/define-read-only-property/dist'),B={};pe(B,"CLI",z());module.exports=B; -/** @license Apache-2.0 */ -/** @license Apache-2.0 */ -/** @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 ffe8370..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../ctor/lib/defaults.json", "../ctor/lib/is_integer.js", "../ctor/lib/validate.js", "../ctor/lib/process.js", "../ctor/lib/console.js", "../ctor/lib/exit_code.js", "../ctor/lib/notifier.js", "../ctor/lib/main.js", "../ctor/lib/index.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"pkg\": {},\n\t\"help\": \"\",\n\t\"title\": true,\n\t\"version\": \"\",\n\t\"updates\": true,\n\t\"argv\": null,\n\t\"options\": {}\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar format = require( '@stdlib/string/format' );\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nmodule.exports = proc;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nmodule.exports = console;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( './process.js' );\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = exitCode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );\nvar noop = require( '@stdlib/utils/noop' );\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nmodule.exports = Notifier;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nvar format = require( '@stdlib/string/format' );\nvar defaults = require( './defaults.json' );\nvar isInteger = require( './is_integer.js' );\nvar validate = require( './validate.js' );\nvar proc = require( './process.js' );\nvar log = require( './console.js' );\nvar exitCode = require( './exit_code.js' );\nvar notifier = require( './notifier.js' );\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nmodule.exports = CLI;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Command-line interface (CLI).\n*\n* @module @stdlib/cli/ctor\n*\n* @example\n* var CLI = require( '@stdlib/cli/ctor' );\n*\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils/define-read-only-property' );\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nsetReadOnly( ns, 'CLI', require( './../ctor' ) );\n\n\n// EXPORTS //\n\nmodule.exports = ns;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,IAAO,CAAC,EACR,KAAQ,GACR,MAAS,GACT,QAAW,GACX,QAAW,GACX,KAAQ,KACR,QAAW,CAAC,CACb,ICRA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAqCA,SAASC,EAAWC,EAAI,CAEvB,OAAS,KAAK,MAAOA,CAAE,IAAMA,CAC9B,CAKAF,EAAO,QAAUC,IC7CjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAK1CC,EAAa,OAAO,UAAU,eAC9BC,EAAU,MAAM,QAkCpB,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAK,OAAOA,GAAY,UAAYA,IAAY,MAAQH,EAASG,CAAQ,EACjE,IAAI,UAAWL,EAAQ,qEAAsEK,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OAAS,EAAI,CAC3B,GAAK,OAAOD,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,gFAAiF+B,CAAK,CAAE,EAEtHE,EAAIF,CACL,MACCE,EAAI,EAEL5B,EAAI,MAAO,YAAa2B,EAAM,OAAQ,EACtC1B,EAAUF,EAAM6B,CAAE,CACnB,CAAC,EAkBDvB,EAAaI,EAAI,UAAW,OAAQ,SAAeiB,EAAO,CACzD,GAAK,UAAU,SAAW,EACzB,OAAO3B,EAAK,KAAM,CAAE,EAErB,GAAK,OAAO2B,GAAS,UAAY,CAAC7B,EAAW6B,CAAK,GAAKA,EAAO,EAC7D,MAAM,IAAI,UAAW/B,EAAQ,qEAAsE+B,CAAK,CAAE,EAE3G3B,EAAK,KAAM2B,CAAK,CACjB,CAAC,EAKDjC,EAAO,QAAUgB,ICrajB,IAAAoB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgDA,IAAIC,GAAO,IAKXD,EAAO,QAAUC,KC3BjB,IAAIC,GAAc,QAAS,yCAA0C,EAUjEC,EAAK,CAAC,EASVD,GAAaC,EAAI,MAAO,GAAuB,EAK/C,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_is_integer", "__commonJSMin", "exports", "module", "isInteger", "x", "require_validate", "__commonJSMin", "exports", "module", "format", "hasOwnProp", "isArray", "validate", "opts", "options", "require_process", "__commonJSMin", "exports", "module", "proc", "require_console", "__commonJSMin", "exports", "module", "require_exit_code", "__commonJSMin", "exports", "module", "proc", "NODE_VERSION", "TIMEOUT", "exitCode", "code", "v", "onTimeout", "require_notifier", "__commonJSMin", "exports", "module", "setReadOnly", "noop", "Notifier", "require_main", "__commonJSMin", "exports", "module", "parseArgs", "format", "defaults", "isInteger", "validate", "proc", "log", "exitCode", "notifier", "defineProperty", "objectKeys", "setReadOnly", "obj", "prop", "value", "CLI", "options", "nopts", "flags", "keys", "opts", "argv", "args", "self", "err", "getArgs", "getFlags", "help", "version", "o", "k", "i", "code", "error", "c", "require_lib", "__commonJSMin", "exports", "module", "main", "setReadOnly", "ns"] -} diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5328a3f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE,I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X,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7a93ff5..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a61b7aa --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 4b35269bc0d0fa2c7f93e4a33e96ee2bf9d98b71 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 04:47:35 +0000 Subject: [PATCH 101/165] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b56187..f5f881a 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.2.1-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From a8ca37f6dcea6e9d48e1417c14f437053c82296e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 Feb 2024 05:33:10 +0000 Subject: [PATCH 105/165] 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 | 207 - .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 | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ----- ctor/test/test.validate.js | 294 - docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 40 - 59 files changed, 6205 insertions(+), 7348 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 8f40da5..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5328a3f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cfc0eb8 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL,EAAKK,KAAgBR,EAASG,EAAKK,MAChE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AASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 7a93ff5..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1dc2e16 --- /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 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 7dc758ba9fd79e9de8e92072694d0b7956b652ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 01:04:35 +0000 Subject: [PATCH 106/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..fedc37c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d95fb05ea2df17df90fd0cf6e1d1133035d9c537 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 01:42:45 +0000 Subject: [PATCH 107/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6225 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5328a3f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.1.1-esm/index.mjs";function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){if(this instanceof e){var n=[null];n.push.apply(n,arguments);var r=Function.bind.apply(t,n);return new r}return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,f=null;function c(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;function h(e,n){return"object"!=typeof n||null===n||g(n)?new TypeError(t("invalid argument. Options argument must be an object. Value: `%s`.",n)):v.call(n,"pkg")&&(e.pkg=n.pkg,"object"!=typeof e.pkg||null===e.pkg||g(e.pkg))?new TypeError(t("invalid option. `%s` option must be an object. Option: `%s`.","pkg",e.pkg)):v.call(n,"help")&&(e.help=n.help,"string"!=typeof e.help)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","help",e.help)):v.call(n,"version")&&(e.version=n.version,"string"!=typeof e.version)?new TypeError(t("invalid option. `%s` option must be a string. Option: `%s`.","version",e.version)):v.call(n,"title")&&(e.title=n.title,"string"!=typeof e.title&&"boolean"!=typeof e.title)?new TypeError(t("invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.","title",e.title)):v.call(n,"updates")&&(e.updates=n.updates,"boolean"!=typeof e.updates)?new TypeError(t("invalid option. `%s` option must be a boolean. Option: `%s`.","updates",e.updates)):v.call(n,"argv")&&(e.argv=n.argv,!g(e.argv))?new TypeError(t("invalid option. `%s` option must be an array. Option: `%s`.","argv",e.argv)):v.call(n,"options")&&(e.options=n.options,"object"!=typeof e.options||null===e.options||g(e.options))?new TypeError(t("invalid option. `%s` option must be a plain object. Option: `%s`.","options",e.options)):null}var d="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}var y=m,w=b;function k(e){if(y===setTimeout)return setTimeout(e,0);if((y===m||!y)&&setTimeout)return y=setTimeout,setTimeout(e,0);try{return y(e,0)}catch(t){try{return y.call(null,e,0)}catch(t){return y.call(this,e,0)}}}"function"==typeof d.setTimeout&&(y=setTimeout),"function"==typeof d.clearTimeout&&(w=clearTimeout);var j,T=[],E=!1,O=-1;function _(){E&&j&&(E=!1,j.length?T=j.concat(T):O=-1,T.length&&x())}function x(){if(!E){var e=k(_);E=!0;for(var t=T.length;t;){for(j=T,T=[];++O1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",r);var oe=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var r={};function o(e){return r[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){r[e]=[].concat(t.alias[e]),r[e].forEach((function(t){r[t]=[e].concat(r[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,r[e]&&[].concat(r[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,r){for(var o=e,i=0;i1){if("number"!=typeof n||!c(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));r=n}else r=1;ee.error("Error: %s",e.message),ne(Y,r)})),ae(le.prototype,"exit",(function(e){if(0===arguments.length)return Y.exit(0);if("number"!=typeof e||!c(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));Y.exit(e)}));var ue={};e(ue,"CLI",le);export{le as CLI,ue as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cfc0eb8..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","validate","opts","options","TypeError","format","call","pkg","help","version","title","updates","argv","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","self","err","arguments","stdout","on","stderr","getArgs","getFlags","bin","name","notifier","notify","error","close","c","Error","message","ns"],"mappings":";;w3BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,QAkCpB,SAASE,EAAUC,EAAMC,GACxB,MAAwB,iBAAZA,GAAoC,OAAZA,GAAoBJ,EAASI,GACzD,IAAIC,UAAWC,EAAQ,qEAAsEF,IAEhGR,EAAWW,KAAMH,EAAS,SAC9BD,EAAKK,IAAMJ,EAAQI,IACM,iBAAbL,EAAKK,KAAiC,OAAbL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AAKa,MAAO/E,GAAQ,EACpB,CAWD,SAASX,IACRK,GAAIoF,MAAOhG,EAAKO,SAChB6E,EAAKa,OACL,CACF,CAkBAvE,GAAayD,GAAIxF,UAAW,SAAS,SAAgBuB,GACpD,GAA0B,IAArBoE,UAAU9B,OAAf,CAIA,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGD,GAAUN,EAAMO,EAJf,MAFAD,GAAUN,EAAM,EAOlB,IA6BAe,GAAayD,GAAIxF,UAAW,SAAS,SAAkBqG,EAAO9E,GAC7D,IAAIgF,EACJ,KAAQF,aAAiBG,OACxB,MAAM,IAAIjG,UAAWC,EAAQ,yEAA0E6F,IAExG,GAAKV,UAAU9B,OAAS,EAAI,CAC3B,GAAqB,iBAATtC,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,gFAAiFe,IAE/GgF,EAAIhF,CACN,MACEgF,EAAI,EAELtF,GAAIoF,MAAO,YAAaA,EAAMI,SAC9BnF,GAAUN,EAAMuF,EACjB,IAkBAxE,GAAayD,GAAIxF,UAAW,QAAQ,SAAeuB,GAClD,GAA0B,IAArBoE,UAAU9B,OACd,OAAO7C,EAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsB5B,EAAW4B,IAAUA,EAAO,EAC7D,MAAM,IAAIhB,UAAWC,EAAQ,qEAAsEe,IAEpGP,EAAKY,KAAML,EACZ,IC5XA,IAAAmF,GAAA,CAAA,EAUA3E,EAAA2E,GAAA,MAAAlB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1dc2e16..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4bd7f297fdad2d41bc6cc8ef4b0f5332a7d73c1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 01:45:27 +0000 Subject: [PATCH 108/165] 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 | 207 - .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 | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7350 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 abc841c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T00:54:00.256Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2130272 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,S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,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index fedc37c..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4b45df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ebfae80ddb18a5ad19cf8eb112683d810081cd6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 00:59:47 +0000 Subject: [PATCH 109/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..fedc37c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From dc2ffcfdc5832ebb8369af831a955604cecb46f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:48:33 +0000 Subject: [PATCH 110/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2130272..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EA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zD,EAAOuB,EAAKC,SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4b45df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 59de0fedda96f836f3725657e5c9cb4dacdb300f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:51:22 +0000 Subject: [PATCH 111/165] 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 | 207 - .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 | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7353 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 121e1c6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T00:48:19.397Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2130272 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mB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GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index fedc37c..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4b45df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From d72bd036ed9d13cb1e471039462a3a972703d0e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:01:08 +0000 Subject: [PATCH 112/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..fedc37c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 53a5a1a4ffb7d05b558b9a88a068bc284ac0033f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:52:11 +0000 Subject: [PATCH 113/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2130272..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBA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,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4b45df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 68a1731bfffa781185f69ac2c8cc414e05eb24d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:55:09 +0000 Subject: [PATCH 114/165] 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 | 206 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7362 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 ec7ab76..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T00:49:12.577Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2130272 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,SAAQ,SAAUxC,GACzD8B,EAAMC,MAAM/B,IAAO,CACtB,IAGC,IAAIyC,EAAU,CAAA,EAEd,SAASC,EAAe1C,GACvB,OAAOyC,E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AAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index fedc37c..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4b45df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From cd52cbbc74b5ef6705e61fc942e9c6e02f99968e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:04:13 +0000 Subject: [PATCH 115/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..fedc37c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 753d159300f52bc11f2a65132cb79251a6f7c378 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:40:40 +0000 Subject: [PATCH 116/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2130272..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,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pE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4b45df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 203fd8b976186aca159e382cdf2c6f72e1291af8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:43:38 +0000 Subject: [PATCH 117/165] 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 | 206 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7362 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 16a5b68..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T00:53:37.621Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2130272 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAA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AAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index fedc37c..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4b45df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From fe8dcdbaf1c4a464fda3f4ba567b0bd641976085 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:06:03 +0000 Subject: [PATCH 118/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..fedc37c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 9735f65893362579f44837d795240690fa9ee9c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:53:43 +0000 Subject: [PATCH 119/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2130272..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAA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AAKkB,MAAO,GAE7BxC,EAAKsB,KAAOzC,GAAKyC,KAAKkB,MAAO,GAE9BlB,EAAOxB,GAAWE,EAAKsB,KAAMtB,EAAKwD,SAGlCzD,EAAOuB,EAAKC,SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4b45df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9e60c825cbf36b367e524fd2a881a86481008cd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:56:53 +0000 Subject: [PATCH 120/165] 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 | 210 - .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 | 46 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7407 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 88da5f6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T00:54:40.810Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2130272 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhB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E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index fedc37c..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4b45df --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 06daa55b915ac2de7629d62de2e68b425cd3792d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 01:06:24 +0000 Subject: [PATCH 121/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 551c1c9..e1cc9c8 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 45471c2be5ff70c5c3061d96fcdff8d463edfc7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 01:49:15 +0000 Subject: [PATCH 122/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2130272..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.1-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,C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WgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4b45df..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From de0e326f352b1e372613e449d945fd67e1420cb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 01:52:36 +0000 Subject: [PATCH 123/165] 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 | 210 - .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 | 354 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7717 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 d627ab6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T00:55:55.344Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,G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AAKsB,KAAOzC,GAAKyC,KAAKkB,MAAO,GAE9BlB,EAAOxB,GAAWE,EAAKsB,KAAMtB,EAAKwD,SAGlCzD,EAAOuB,EAAKC,SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index e1cc9c8..c24c3e3 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.2.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From e00216dc063ba51f4ccf563700f7c744a675d177 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Aug 2024 22:09:20 +0000 Subject: [PATCH 124/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a212cb9..76ec3b1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c2a3feb415f6d4714d1e08f4288ebb64423ee0a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Aug 2024 22:31:39 +0000 Subject: [PATCH 125/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ea2e518..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,SAAQ,SAAUxC,GACzD8B,EAAMC,MAAM/B,IAAO,CACtB,IAGC,IAAIyC,EAAU,CAAA,EAEd,SAASC,EAAe1C,GACvB,OAAOyC,EAAQzC,GAAK2C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E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cd2b71922e19fc6a2421934f085d0c7b72241728 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Aug 2024 22:34:54 +0000 Subject: [PATCH 126/165] 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 | 210 - .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 | 312 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 59 files changed, 4870 insertions(+), 7674 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC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0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 76ec3b1..7cdd0d5 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 4921027a8fa19f3f3a42f2e5c596b23ee5fae335 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 18 Aug 2024 22:46:22 +0000 Subject: [PATCH 127/165] Update README.md for ESM bundle v0.3.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9a1d31..c061c8e 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.1-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From 67928e01a86fe98eccc4a1f8060591dbaa83226c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 01:56:17 +0000 Subject: [PATCH 131/165] 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 | 210 - .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 | 322 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7685 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 81a42a6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T01:02:18.550Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAA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AAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 76ec3b1..7cdd0d5 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 04d1b4d58b29f1e355704425117b1932d072bb83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 01:12:18 +0000 Subject: [PATCH 132/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a212cb9..76ec3b1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1a953a2b90f187ab903faa814317193bc1655bb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 01:41:53 +0000 Subject: [PATCH 133/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ea2e518..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC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B,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 26f2b9d3457beeac0d0fd6a90d94befb82aa1bce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 01:45:09 +0000 Subject: [PATCH 134/165] 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 | 210 - .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 | 322 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7685 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 dccc03d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T01:02:16.945Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SA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IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 76ec3b1..7cdd0d5 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From f30d3cd069c69e3f575bda89db878be792b955e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 01:12:25 +0000 Subject: [PATCH 135/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a212cb9..76ec3b1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From a19bd2025507a70b3882ad943b6fea2e02e9f3ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 01:48:39 +0000 Subject: [PATCH 136/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ea2e518..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GA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,SAGlCzD,EAAOuB,EAAKC,SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From eea91b79889d1926d91b2b6493f6d162ab0b113a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 01:51:52 +0000 Subject: [PATCH 137/165] 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 | 210 - .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 | 322 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7685 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 1963de5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T01:03:44.289Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IA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A,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 76ec3b1..7cdd0d5 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.1", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From bf3a2b32789c3bfb141c4268fc73c56f0e84a772 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 19:49:25 +0000 Subject: [PATCH 138/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 561a2b6..5d4fd09 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 55d2acb05a06d994f5e7aebbaf1db1d6d49dec1e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 20:32:05 +0000 Subject: [PATCH 139/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ea2e518..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAa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IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1f389da75ec870fe283164ae43b641fb3202f88e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 20:35:19 +0000 Subject: [PATCH 140/165] 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 | 210 - .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 | 322 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 59 files changed, 4870 insertions(+), 7684 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGh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9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 5d4fd09..c29bf72 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.2", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ce6e529bf5077b556e6b5bec3e825768f579a5eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 20:36:11 +0000 Subject: [PATCH 141/165] Update README.md for ESM bundle v0.3.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8f107a1..aae483c 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.2-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.2-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From 4169c28f5270c198cb53462abfface8db794f120 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 21:12:58 +0000 Subject: [PATCH 145/165] 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 | 210 - .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 | 332 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------- ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 +++++++++++++++++++++ test/test.js | 40 - 59 files changed, 4870 insertions(+), 7694 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EA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SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 8e4b732db9b05f67802585a29fe21172494ed6d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Nov 2024 21:26:44 +0000 Subject: [PATCH 146/165] Update README.md for ESM bundle v0.3.3 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27aa9d2..bb51a22 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ limitations under the License. ## Usage ```javascript -import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import ns from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.3-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@esm/index.mjs'; +import { CLI } from 'https://cdn.jsdelivr.net/gh/stdlib-js/cli@v0.3.3-esm/index.mjs'; ``` #### ns @@ -91,7 +91,7 @@ The namespace contains the following: - - - - From 1a918dda6e2f1b1d62035f115b1d807f0fc6d23b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 01:58:51 +0000 Subject: [PATCH 150/165] 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 | 210 - .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 | 342 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 61 files changed, 4870 insertions(+), 7810 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 9190d6a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T01:10:01.136Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ea2e518 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,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,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 7f35e3b0abe14af54333b7eddbb9b9be00261030 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:41:09 +0000 Subject: [PATCH 151/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 27ac1af..155b89d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c79ca880d188953c7b00621a4a2f346a33e236ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:50:59 +0000 Subject: [PATCH 152/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ea2e518..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM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pF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c1351cedc5aa57db0c4e5f18d0fc59bcfb134b1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 20 Jan 2025 01:54:39 +0000 Subject: [PATCH 153/165] 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 | 210 - .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 | 342 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 61 files changed, 4870 insertions(+), 7809 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 a2c4682..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-20T01:37:47.848Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7dfe337..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dfcbbdc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,SAAQ,SAAUxC,GACzD8B,EAAMC,MAAM/B,IAAO,CACtB,IAG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AsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From d581f1b2b4d5d6168cf72b1ce2c10318d03612d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 01:52:02 +0000 Subject: [PATCH 154/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 27ac1af..155b89d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ad34b12c109bbf5b916bb027e39d15037f3f1863 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:39:15 +0000 Subject: [PATCH 155/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dfcbbdc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAW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GGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 114f032d4398c939bd0262266913e817d29eaae3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:44:22 +0000 Subject: [PATCH 156/165] 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 | 210 - .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 | 258 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 54 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 61 files changed, 4870 insertions(+), 7729 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 982ea17..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:33:34.829Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d47aef8..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index f245a17..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 4700630..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index fae1bb8..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 5f46bcf..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 683a1df..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f769dc5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var g=Object.prototype.hasOwnProperty,v=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dde0873 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;qzBAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,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BhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..66704d6 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 4703875..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); From 43bb78b255ca1f8a821acbee0dab17452f1f860a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 21:10:19 +0000 Subject: [PATCH 157/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 27ac1af..155b89d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c2c94c6481b3272e9695cef1a01273f514f6d9c0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 21:10:41 +0000 Subject: [PATCH 158/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f769dc5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var g=Object.prototype.hasOwnProperty,v=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dde0873..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;qzBAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC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ArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 66704d6..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 060b357c69d865670c0b9fbfa12168ee5b664bb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 21:15:28 +0000 Subject: [PATCH 159/165] Auto-generated commit --- .editorconfig | 180 - .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 | 210 - .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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 310 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 53 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7784 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 .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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d47aef8..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index 60597f3..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 938bf3f..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index bc66e95..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 76ce280..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 3c8574e..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dfcbbdc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,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Gd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e682e93..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.strictEqual( keys.length > 0, true, 'has keys' ); - t.end(); -}); From d716c982937a907520a0b6c500001290ee914e23 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Dec 2025 02:20:21 +0000 Subject: [PATCH 160/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 27ac1af..155b89d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -79,4 +80,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d42c42b9b67f7cbbf624ea207a191053f86be384 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Dec 2025 02:20:37 +0000 Subject: [PATCH 161/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dfcbbdc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EA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,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f4645b95adf014694940ea71f20329e52c8863a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Dec 2025 02:25:28 +0000 Subject: [PATCH 162/165] Auto-generated commit --- .editorconfig | 180 - .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 | 210 - .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 | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 310 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 53 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 59 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 60 files changed, 4870 insertions(+), 7784 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 .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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d47aef8..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index 60597f3..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 938bf3f..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index bc66e95..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 76ce280..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 3c8574e..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dfcbbdc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,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7BxC,EAAKsB,KAAOzC,GAAKyC,KAAKkB,MAAO,GAE9BlB,EAAOxB,GAAWE,EAAKsB,KAAMtB,EAAKwD,SAGlCzD,EAAOuB,EAAKC,SACLD,EAAKC,GACZtB,EAAQqB,GAGGuC,KACHlE,KAAKkE,KAAM,GAGd5D,EAAM8D,QACHpE,KAAKoE,UAENpE,IA6DR,CAkBAC,GAAa2D,GAAI9E,UAAW,SAAS,SAAgBW,GACpD,GAA0B,IAArBuE,UAAU/B,OAAf,CAIA,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGD,GAAUN,GAAMO,EAJf,MAFAD,GAAUN,GAAM,EAOlB,IA6BAe,GAAa2D,GAAI9E,UAAW,SAAS,SAAkB+F,EAAOpF,GAC7D,IAAI0F,EACJ,KAAQN,aAAiBO,OACxB,MAAM,IAAId,UAAWC,EAAQ,yEAA0EM,IAExG,GAAKb,UAAU/B,OAAS,EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index 155b89d..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -75,9 +23,8 @@ "command-line", "interface" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d61ef8c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e682e93..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.strictEqual( keys.length > 0, true, 'has keys' ); - t.end(); -}); From ee81c83ca307e16ee129b6ef4afbda5556f152cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Feb 2026 02:53:19 +0000 Subject: [PATCH 163/165] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 85fb548..a67f185 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "dependencies": { "@stdlib/string": "github:stdlib-js/string#main", "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, "devDependencies": { "@stdlib/assert": "github:stdlib-js/assert#main", @@ -78,4 +79,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From bb5fc266cfc5af0b4422222a87311013e57498c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Feb 2026 04:18:03 +0000 Subject: [PATCH 164/165] Remove files --- index.d.ts | 43 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4890 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 3176df5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable max-lines */ - -import CLI = require( './../../ctor' ); - -/** -* Interface describing the `cli` namespace. -*/ -interface Namespace { - /** - * Command-line interface. - */ - CLI: typeof CLI; -} - -/** -* Command-line interface. -*/ -declare var ns: Namespace; - - -// EXPORTS // - -export = ns; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dfcbbdc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.2-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index af99b2d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,SAAQ,SAAUxC,GACzD8B,EAAMC,MAAM/B,IAAO,CACtB,IAGC,IAAIyC,EAAU,CAAA,EAEd,SAASC,EAAe1C,GACvB,OAAOyC,EAAQzC,GA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AiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d61ef8c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2dd909b7545fb2ae93e376ec003587c18377f10b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 16 Feb 2026 04:23:49 +0000 Subject: [PATCH 165/165] 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 | 821 --- .github/workflows/publish.yml | 219 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 310 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - branches.md | 56 - ctor/README.md | 456 -- ctor/benchmark/benchmark.js | 145 - ctor/docs/types/index.d.ts | 209 - ctor/docs/types/test.ts | 108 - ctor/examples/fixtures/main.js | 34 - ctor/examples/fixtures/opts.json | 14 - ctor/examples/fixtures/usage.txt | 8 - ctor/examples/index.js | 48 - ctor/lib/console.js | 23 - ctor/lib/defaults.json | 9 - ctor/lib/exit_code.js | 79 - ctor/lib/index.js | 53 - ctor/lib/is_integer.js | 46 - ctor/lib/main.js | 422 -- ctor/lib/notifier.js | 61 - ctor/lib/process.js | 28 - ctor/lib/validate.js | 115 - ctor/package.json | 69 - ctor/test/fixtures/stderr.js | 61 - ctor/test/fixtures/stdout.js | 61 - ctor/test/fixtures/usage.txt | 8 - ctor/test/test.exit_code.js | 125 - ctor/test/test.js | 1468 ------ ctor/test/test.validate.js | 294 -- docs/types/test.ts | 29 - examples/index.js | 24 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 51 - package.json | 58 +- stats.html | 4842 ++++++++++++++++++ test/test.js | 40 - 61 files changed, 4870 insertions(+), 7877 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 branches.md delete mode 100644 ctor/README.md delete mode 100644 ctor/benchmark/benchmark.js delete mode 100644 ctor/docs/types/index.d.ts delete mode 100644 ctor/docs/types/test.ts delete mode 100644 ctor/examples/fixtures/main.js delete mode 100644 ctor/examples/fixtures/opts.json delete mode 100644 ctor/examples/fixtures/usage.txt delete mode 100644 ctor/examples/index.js delete mode 100644 ctor/lib/console.js delete mode 100644 ctor/lib/defaults.json delete mode 100644 ctor/lib/exit_code.js delete mode 100644 ctor/lib/index.js delete mode 100644 ctor/lib/is_integer.js delete mode 100644 ctor/lib/main.js delete mode 100644 ctor/lib/notifier.js delete mode 100644 ctor/lib/process.js delete mode 100644 ctor/lib/validate.js delete mode 100644 ctor/package.json delete mode 100644 ctor/test/fixtures/stderr.js delete mode 100644 ctor/test/fixtures/stdout.js delete mode 100644 ctor/test/fixtures/usage.txt delete mode 100644 ctor/test/test.exit_code.js delete mode 100644 ctor/test/test.js delete mode 100644 ctor/test/test.validate.js delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (100%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js create mode 100644 stats.html 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 cd973af..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-02-16T02:16:47.852Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d47aef8..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/cli) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 45b2a2b..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/cli) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 13ac9c6..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: '56 20 * * 3' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -124,7 +121,7 @@ console.log( objectKeys( ns ) ); ## 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]. 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/branches.md b/branches.md deleted file mode 100644 index d3ed426..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/cli" -%% click B href "https://github.com/stdlib-js/cli/tree/main" -%% click C href "https://github.com/stdlib-js/cli/tree/production" -%% click D href "https://github.com/stdlib-js/cli/tree/esm" -%% click E href "https://github.com/stdlib-js/cli/tree/deno" -%% click F href "https://github.com/stdlib-js/cli/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/cli -[production-url]: https://github.com/stdlib-js/cli/tree/production -[deno-url]: https://github.com/stdlib-js/cli/tree/deno -[deno-readme]: https://github.com/stdlib-js/cli/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/cli/tree/umd -[umd-readme]: https://github.com/stdlib-js/cli/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/cli/tree/esm -[esm-readme]: https://github.com/stdlib-js/cli/blob/esm/README.md \ No newline at end of file diff --git a/ctor/README.md b/ctor/README.md deleted file mode 100644 index ffa50c1..0000000 --- a/ctor/README.md +++ /dev/null @@ -1,456 +0,0 @@ - - -# CLI - -> Command-line interface. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var CLI = require( '@stdlib/cli/ctor' ); -``` - -#### CLI( \[options] ) - -Command-line interface (CLI) constructor. - -```javascript -var cli = new CLI(); -// returns -``` - -The constructor accepts the following `options`: - -- **pkg**: package meta data, such as a `package.json` object. -- **version**: command-line interface version. Default: `pkg.version`. -- **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. -- **help**: help text. Default: `''`. -- **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. -- **argv**: an `array` of command-line arguments. Default: `process.argv`. -- **options**: command-line argument parser options. - -To provide package meta data, such as the package `name` and `version`, set the `pkg` option. - -```javascript -var opts = { - 'pkg': require( './package.json' ) -}; - -var cli = new CLI( opts ); -// returns -``` - -To specify a particular command-line interface version (overriding package meta data), set the `version` option. - -```javascript -var opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.1.1' - }, - 'version': '1.1.1-beta' -}; - -var cli = new CLI( opts ); -// returns - -cli.version(); -// => 1.1.1-beta -``` - -By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. - -```javascript -var proc = require( 'process' ); - -var opts = { - 'title': 'beep-boop' -}; - -var cli = new CLI( opts ); -// returns - -console.log( proc.title ); -// => 'beep-boop' -``` - -To disable setting the process title, set the `title` option to `false`. - -```javascript -var opts = { - 'title': false -}; - -var cli = new CLI( opts ); -// returns -``` - -When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. - - - -```javascript -var opts = { - 'help': 'Usage: boop [options] ', - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '--help' - ] -}; - -var cli = new CLI( opts ); -// => Usage: boop [options] -``` - -By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. - -```javascript -var opts = { - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - 'b', - 'c' - ] -}; - -var cli = new CLI( opts ); - -var args = cli.args(); -// returns [ 'a', 'b', 'c' ] -``` - -To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. - -```javascript -var opts = { - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'string': [ - 'output' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ], - 'output': [ - 'o' - ] - } - }, - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - '-o=bar.js' - ] -}; - -var cli = new CLI( opts ); - -var flags = cli.flags(); -/* returns - { - 'h': false, - 'help': false, - 'V': false, - 'version': false, - 'o': 'bar.js', - 'output': 'bar.js' - } -*/ -``` - -By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. - -```javascript -var opts = { - 'updates': false -}; - -var cli = new CLI( opts ); -// returns -``` - -* * * - -### Prototype Methods - -#### CLI.prototype.close( \[code] ) - -Gracefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Gracefully exit: -cli.close(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.close( 1 ); -``` - -#### CLI.prototype.error( error\[, code] ) - -Prints an error message to `stderr` and exits a command-line interface and the calling process. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err ); -``` - -When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// ... - -// Create a new error object: -var err = new Error( 'invalid argument' ); - -// Exit due to the error: -cli.error( err, 2 ); -``` - -#### CLI.prototype.exit( \[code] ) - -Forcefully exits a command-line interface and the calling process. - -```javascript -var cli = new CLI(); - -// Forcefully exit: -cli.exit(); -``` - -To specify an exit code, provide a `code` argument. - - - -```javascript -var cli = new CLI(); - -// Set the exit code to `1`: -cli.exit( 1 ); -``` - -* * * - -### Instance Methods - -#### cli.args() - -Returns a list of command-line arguments. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - 'd' - ] -}); - -var args = cli.args(); -// returns [ 'a', 'd' ] -``` - -#### cli.flags() - -Returns command-line flags. - -```javascript -var cli = new CLI({ - 'argv': [ - '/usr/local/bin/node', - 'foo.js', - 'a', - '--b', - 'c', - '-def', - '--g=h', - 'i' - ] -}); - -var flags = cli.flags(); -// returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } -``` - -#### cli.help( \[code] ) - -Prints help text to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'help': 'Usage: beep [options] ' -}); - -cli.help(); -// => Usage: beep [options] -``` - -By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. - -#### cli.version() - -Prints the command-line interface version to `stderr` and then exits the calling process. - -```javascript -var cli = new CLI({ - 'version': '1.1.1' -}); - -cli.version(); -// => 1.1.1 -``` - -
- - - - - -* * * - -
- -## Notes - -- When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. -- When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file. - -
- - - - - -* * * - -
- -## Examples - - - - - -```javascript -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( '@stdlib/cli/ctor' ); -var main = require( './examples/fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './package.json' ), - 'options': require( './examples/fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/ctor/benchmark/benchmark.js b/ctor/benchmark/benchmark.js deleted file mode 100644 index 0edb275..0000000 --- a/ctor/benchmark/benchmark.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var CLI = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var cli; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var ctor; - var cli; - var i; - - ctor = CLI; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = ctor(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,options', function benchmark( b ) { - var opts; - var cli; - var i; - - opts = { - 'pkg': { - 'name': 'beep', - 'version': '1.0.0' - }, - 'help': 'Usage: beep [options] ', - 'options': {}, - 'version': '1.0.0', - 'updates': true, - 'argv': [], - 'title': true - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - cli = new CLI( opts ); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - } - b.toc(); - if ( !( cli instanceof CLI ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':args', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.args(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':flags', function benchmark( b ) { - var out; - var cli; - var i; - - cli = new CLI(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = cli.flags(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/ctor/docs/types/index.d.ts b/ctor/docs/types/index.d.ts deleted file mode 100644 index f55df2d..0000000 --- a/ctor/docs/types/index.d.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Package meta information (package.json) (default: {}). - */ - pkg?: any; - - /** - * Command-line interface version. - */ - version?: string; - - /** - * Help text (default: ''). - */ - help?: string; - - /** - * Process title or a boolean indicating whether to set the process title (default: true). - */ - title?: string | boolean; - - /** - * Boolean indicating whether to check if a command-line interface is an outdated version (default: true). - */ - updates?: boolean; - - /** - * Command-line arguments. - */ - argv?: Array; - - /** - * Command-line interface options (default: {}). - */ - options?: Options; -} - -/** -* Command-line interface. -*/ -declare class CLI { - /** - * Command-line interface constructor. - * - * @param options - options - * @param options.pkg - package meta information (package.json) (default: {}) - * @param options.version - command-line interface version - * @param options.help - help text (default: '') - * @param options.title - process title or a boolean indicating whether to set the process title (default: true) - * @param options.updates - boolean indicating whether to check if a command-line interface is an outdated version (default: true) - * @param options.argv - command-line arguments - * @param options.options - command-line interface options (default: {}) - * @throws must provide valid options - * @returns command-line interface - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ), - * 'help': 'Usage: beep [options] ', - * 'title': 'foo', - * 'updates': true, - * 'options': { - * 'boolean': [ - * 'help', - * 'version' - * ] - * } - * }; - * var cli = new CLI( opts ); - * // returns - * - * cli.close(); - */ - constructor( options?: Options ); - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - args(): Array; - - /** - * Returns parsed command-line arguments. - * - * @returns parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - flags(): Array; - - /** - * Prints usage information and exits the process. - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - help(): void; - - /** - * Prints the command-line interface version and exits the process. - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - version(): void; - - /** - * Gracefully exits the command-line interface and the calling process. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Gracefully exit: - * cli.close(); - */ - close( code?: number ): void; - - /** - * Exits the command-line interface and the calling process due to an error. - * - * ## Notes - * - * - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. - * - * @param error - error object - * @param code - exit code (default: 1) - * @throws second argument must be a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // ... - * - * // Create an error object: - * var err = new Error( 'invalid operation' ); - * - * // Exit the process: - * cli.error( err, 0 ); - */ - error( error: Error, code?: number ): void; - - /** - * Forces the command-line interface (and the calling process) to exit. - * - * @param code - exit code (default: 0) - * @throws must provide a nonnegative integer - * - * @example - * var cli = new CLI(); - * - * // Forcefully exit: - * cli.exit(); - */ - exit( code?: number ): void; -} - - -// EXPORTS // - -export = CLI; diff --git a/ctor/docs/types/test.ts b/ctor/docs/types/test.ts deleted file mode 100644 index bae543e..0000000 --- a/ctor/docs/types/test.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import CLI = require( './index' ); - - -// TESTS // - -// The function returns a command-line interface... -{ - new CLI(); // $ExpectType CLI - new CLI( { 'updates': false } ); // $ExpectType CLI -} - -// The compiler throws an error if the constructor function is provided an argument that is not an options object... -{ - new CLI( 123 ); // $ExpectError - new CLI( 'abc' ); // $ExpectError - new CLI( null ); // $ExpectError - new CLI( true ); // $ExpectError - new CLI( false ); // $ExpectError - new CLI( [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `version` option which is not a string... -{ - new CLI( { 'version': 123 } ); // $ExpectError - new CLI( { 'version': true } ); // $ExpectError - new CLI( { 'version': false } ); // $ExpectError - new CLI( { 'version': null } ); // $ExpectError - new CLI( { 'version': [] } ); // $ExpectError - new CLI( { 'version': {} } ); // $ExpectError - new CLI( { 'version': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `help` option which is not a string... -{ - new CLI( { 'help': 123 } ); // $ExpectError - new CLI( { 'help': true } ); // $ExpectError - new CLI( { 'help': false } ); // $ExpectError - new CLI( { 'help': null } ); // $ExpectError - new CLI( { 'help': [] } ); // $ExpectError - new CLI( { 'help': {} } ); // $ExpectError - new CLI( { 'help': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `title` option which is neither a string nor boolean... -{ - new CLI( { 'title': 123 } ); // $ExpectError - new CLI( { 'title': null } ); // $ExpectError - new CLI( { 'title': [] } ); // $ExpectError - new CLI( { 'title': {} } ); // $ExpectError - new CLI( { 'title': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `updates` option which is not a boolean... -{ - new CLI( { 'updates': 123 } ); // $ExpectError - new CLI( { 'updates': 'abc' } ); // $ExpectError - new CLI( { 'updates': null } ); // $ExpectError - new CLI( { 'updates': [] } ); // $ExpectError - new CLI( { 'updates': {} } ); // $ExpectError - new CLI( { 'updates': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `argv` option which is not an array... -{ - new CLI( { 'argv': 'abc' } ); // $ExpectError - new CLI( { 'argv': 123 } ); // $ExpectError - new CLI( { 'argv': true } ); // $ExpectError - new CLI( { 'argv': false } ); // $ExpectError - new CLI( { 'argv': null } ); // $ExpectError - new CLI( { 'argv': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `options` option which is not an options object... -{ - new CLI( { 'options': 'abc' } ); // $ExpectError - new CLI( { 'options': 123 } ); // $ExpectError - new CLI( { 'options': true } ); // $ExpectError - new CLI( { 'options': false } ); // $ExpectError - new CLI( { 'options': null } ); // $ExpectError - new CLI( { 'options': [] } ); // $ExpectError - new CLI( { 'options': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the constructor function is provided more than one argument... -{ - new CLI( {}, {} ); // $ExpectError - new CLI( {}, {}, {} ); // $ExpectError -} diff --git a/ctor/examples/fixtures/main.js b/ctor/examples/fixtures/main.js deleted file mode 100644 index d730e8a..0000000 --- a/ctor/examples/fixtures/main.js +++ /dev/null @@ -1,34 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Prints to `stdout`. -* -* @private -* @param {string} str - string to print -*/ -function stdout( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = stdout; diff --git a/ctor/examples/fixtures/opts.json b/ctor/examples/fixtures/opts.json deleted file mode 100644 index 60597f3..0000000 --- a/ctor/examples/fixtures/opts.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} diff --git a/ctor/examples/fixtures/usage.txt b/ctor/examples/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/examples/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/examples/index.js b/ctor/examples/index.js deleted file mode 100644 index 0ed773f..0000000 --- a/ctor/examples/index.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'; - -var join = require( 'path' ).join; -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var CLI = require( './../lib' ); -var main = require( './fixtures/main.js' ); - -// Load help text: -var fopts = { - 'encoding': 'utf8' -}; -var help = readFileSync( join( __dirname, 'fixtures', 'usage.txt' ), fopts ); - -// Set the command-line interface options: -var opts = { - 'pkg': require( './../package.json' ), - 'options': require( './fixtures/opts.json' ), - 'help': help, - 'title': true, - 'updates': true -}; - -// Create a new command-line interface: -var cli = new CLI( opts ); - -// Run main: -main( 'beep' ); - -// Close: -cli.close( 0 ); diff --git a/ctor/lib/console.js b/ctor/lib/console.js deleted file mode 100644 index 3a2e2de..0000000 --- a/ctor/lib/console.js +++ /dev/null @@ -1,23 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// EXPORTS // - -module.exports = console; diff --git a/ctor/lib/defaults.json b/ctor/lib/defaults.json deleted file mode 100644 index 938bf3f..0000000 --- a/ctor/lib/defaults.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "pkg": {}, - "help": "", - "title": true, - "version": "", - "updates": true, - "argv": null, - "options": {} -} diff --git a/ctor/lib/exit_code.js b/ctor/lib/exit_code.js deleted file mode 100644 index 0e8dacd..0000000 --- a/ctor/lib/exit_code.js +++ /dev/null @@ -1,79 +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. -*/ - -'use strict'; - -// MODULES // - -var proc = require( './process.js' ); - - -// VARIABLES // - -var NODE_VERSION = proc.versions.node; -var TIMEOUT = 10; // ms - - -// MAIN // - -/** -* Sets the process exit code. -* -* @private -* @param {Object} proc - process object -* @param {NonNegativeInteger} code - exit code -* @returns {void} -*/ -function exitCode( proc, code ) { - var v; - - // Handle old Node.js versions lacking `process.exitCode` support... - v = NODE_VERSION.split( '.' ); - v[ 0 ] = parseInt( v[ 0 ], 10 ); - v[ 1 ] = parseInt( v[ 1 ], 10 ); - - // Case: >0.x.x - if ( v[ 0 ] > 0 ) { - proc.exitCode = code; - return; - } - // Case: >0.10.x - if ( v[ 1 ] > 10 ) { - proc.exitCode = code; - return; - } - // Case: <= 0.10.x - proc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions - - // No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)... - setTimeout( onTimeout, TIMEOUT ); - - /** - * Callback invoked during a subsequent turn of the event loop. - * - * @private - */ - function onTimeout() { - proc.exit( code ); - } -} - - -// EXPORTS // - -module.exports = exitCode; diff --git a/ctor/lib/index.js b/ctor/lib/index.js deleted file mode 100644 index bc66e95..0000000 --- a/ctor/lib/index.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Command-line interface (CLI). -* -* @module @stdlib/cli/ctor -* -* @example -* var CLI = require( '@stdlib/cli/ctor' ); -* -* var opts = { -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/ctor/lib/is_integer.js b/ctor/lib/is_integer.js deleted file mode 100644 index 3b60d85..0000000 --- a/ctor/lib/is_integer.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Tests if a finite double-precision floating-point number is an integer. -* -* @private -* @param {number} x - value to test -* @returns {boolean} boolean indicating whether the value is an integer -* -* @example -* var bool = isInteger( 1.0 ); -* // returns true -* -* @example -* var bool = isInteger( 3.14 ); -* // returns false -*/ -function isInteger( x ) { - // NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies. - return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math -} - - -// EXPORTS // - -module.exports = isInteger; diff --git a/ctor/lib/main.js b/ctor/lib/main.js deleted file mode 100644 index 881d710..0000000 --- a/ctor/lib/main.js +++ /dev/null @@ -1,422 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 stdlib/jsdoc-doctest, no-restricted-syntax */ - -'use strict'; - -// MODULES // - -var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.json' ); -var isInteger = require( './is_integer.js' ); -var validate = require( './validate.js' ); -var proc = require( './process.js' ); -var log = require( './console.js' ); -var exitCode = require( './exit_code.js' ); -var notifier = require( './notifier.js' ); - - -// VARIABLES // - -// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x. -var defineProperty = Object.defineProperty; -var objectKeys = Object.keys; - - -// FUNCTIONS // - -/** -* Defines a read-only non-enumerable property. -* -* @private -* @param {Object} obj - object on which to define the property -* @param {(string|symbol)} prop - property name -* @param {*} value - value to set -* -* @example -* var obj = {}; -* -* setReadOnly( obj, 'foo', 'bar' ); -* -* try { -* obj.foo = 'boop'; -* } catch ( err ) { -* console.error( err.message ); -* } -*/ -function setReadOnly( obj, prop, value ) { - defineProperty( obj, prop, { - 'configurable': false, - 'enumerable': false, - 'writable': false, - 'value': value - }); -} - - -// MAIN // - -/** -* Command-line interface constructor. -* -* @constructor -* @param {Options} [options] - options -* @param {Object} [options.pkg={}] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help=""] - help text -* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options={}] - command-line interface options -* @throws {TypeError} must provide an object -* @throws {TypeError} must provide valid options -* @returns {CLI} command-line interface -* -* @example -* var opts = { -* 'pkg': require( './path/to/package.json' ), -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true, -* 'options': { -* 'boolean': [ -* 'help', -* 'version' -* ] -* } -* }; -* var cli = new CLI( opts ); -* // returns -* -* cli.close(); -*/ -function CLI( options ) { - var nopts; - var flags; - var keys; - var opts; - var argv; - var args; - var self; - var err; - if ( !( this instanceof CLI ) ) { - if ( arguments.length ) { - return new CLI( options ); - } - return new CLI(); - } - opts = { - 'pkg': {}, - 'help': defaults.help, - 'title': defaults.title, - 'version': defaults.version, - 'updates': defaults.updates, - 'argv': defaults.argv, - 'options': {} - }; - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - self = this; - - // Force the process to exit if an error is encountered when writing to `stdout` or `stderr`: - proc.stdout.on( 'error', proc.exit ); - proc.stderr.on( 'error', proc.exit ); - - /** - * Returns parsed command-line arguments. - * - * @name args - * @memberof CLI# - * @type {Function} - * @returns {StringArray} parsed command-line arguments - * - * @example - * var cli = new CLI(); - * - * var args = cli.args(); - * // returns - */ - setReadOnly( this, 'args', getArgs ); - - /** - * Returns parsed command-line flags. - * - * @name flags - * @memberof CLI# - * @type {Function} - * @returns {Object} parsed command-line flags - * - * @example - * var cli = new CLI(); - * - * var flags = cli.flags(); - * // returns - */ - setReadOnly( this, 'flags', getFlags ); - - /** - * Prints usage information and exits the process. - * - * @name help - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'help': 'Usage: beep [options] ' - * }; - * var cli = new CLI( opts ); - * - * cli.help(); - * // => 'Usage: beep [options] ' - */ - setReadOnly( this, 'help', help ); - - /** - * Prints the command-line interface version and exits the process. - * - * @name version - * @memberof CLI# - * @type {Function} - * - * @example - * var opts = { - * 'pkg': require( './path/to/package.json' ) - * }; - * var cli = new CLI( opts ); - * - * cli.version(); - * // => '#.#.#' - */ - setReadOnly( this, 'version', version ); - - // Check whether to set the process title... - if ( opts.title === true && opts.pkg ) { - if ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) { - keys = objectKeys( opts.pkg.bin ); - - // Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry. - proc.title = keys[ 0 ]; - } else if ( opts.pkg.name ) { - proc.title = opts.pkg.name; - } - } else if ( opts.title ) { - proc.title = opts.title; - } - // Check whether to notify the user of a new CLI version... - if ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) { - nopts = { - 'pkg': opts.pkg - }; - notifier( nopts ).notify(); - } - // Determine the command-line interface version... - if ( !opts.version && opts.pkg && opts.pkg.version ) { - opts.version = opts.pkg.version; - } - // Parse command-line arguments: - if ( opts.argv ) { - opts.argv = opts.argv.slice( 2 ); - } else { - opts.argv = proc.argv.slice( 2 ); - } - argv = parseArgs( opts.argv, opts.options ); - - // Cache parsed arguments: - args = argv._; - delete argv._; - flags = argv; - - // Determine whether to print help text... - if ( flags.help ) { - return this.help( 0 ); - } - // Determine whether to print the version... - if ( flags.version ) { - return this.version(); - } - return this; - - /** - * Returns parsed command-line arguments. - * - * @private - * @returns {StringArray} parsed command-line arguments - */ - function getArgs() { - return args.slice(); - } - - /** - * Returns parsed command-line flags. - * - * @private - * @returns {Object} parsed command-line flags - */ - function getFlags() { - var keys; - var o; - var k; - var i; - - keys = objectKeys( flags ); - o = {}; - for ( i = 0; i < keys.length; i++ ) { - k = keys[ i ]; - o[ k ] = flags[ k ]; - } - return o; - } - - /** - * Prints usage information. - * - * ## Notes - * - * - Upon printing usage information, the function forces the process to exit. - * - * @private - * @param {NonNegativeInteger} [code=0] - exit code - */ - function help( code ) { - log.error( opts.help ); - self.close( code || 0 ); - } - - /** - * Prints the command-line interface version. - * - * ## Notes - * - * - Upon printing the version, the function forces the process to exit. - * - * @private - */ - function version() { - log.error( opts.version ); - self.close(); - } -} - -/** -* Gracefully exits the command-line interface and the calling process. -* -* @name close -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Gracefully exit: -* cli.close(); -*/ -setReadOnly( CLI.prototype, 'close', function close( code ) { - if ( arguments.length === 0 ) { - exitCode( proc, 0 ); - return; - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - exitCode( proc, code ); -}); - -/** -* Exits the command-line interface and the calling process due to an error. -* -* ## Notes -* -* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process. -* -* @name error -* @memberof CLI.prototype -* @type {Function} -* @param {Error} error - error object -* @param {NonNegativeInteger} [code=1] - exit code -* @throws {TypeError} first argument must be an error object -* @throws {TypeError} second argument must be a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // ... -* -* // Create an error object: -* var err = new Error( 'invalid operation' ); -* -* // Exit the process: -* cli.error( err, 0 ); -*/ -setReadOnly( CLI.prototype, 'error', function onError( error, code ) { - var c; - if ( !( error instanceof Error ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) ); - } - if ( arguments.length > 1 ) { - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) ); - } - c = code; - } else { - c = 1; - } - log.error( 'Error: %s', error.message ); - exitCode( proc, c ); -}); - -/** -* Forces the command-line interface (and the calling process) to exit. -* -* @name exit -* @memberof CLI.prototype -* @type {Function} -* @param {NonNegativeInteger} [code=0] - exit code -* @throws {TypeError} must provide a nonnegative integer -* @returns {void} -* -* @example -* var cli = new CLI(); -* -* // Forcefully exit: -* cli.exit(); -*/ -setReadOnly( CLI.prototype, 'exit', function exit( code ) { - if ( arguments.length === 0 ) { - return proc.exit( 0 ); - } - if ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) { - throw new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) ); - } - proc.exit( code ); -}); - - -// EXPORTS // - -module.exports = CLI; diff --git a/ctor/lib/notifier.js b/ctor/lib/notifier.js deleted file mode 100644 index 63e74f8..0000000 --- a/ctor/lib/notifier.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// FIXME: remove this stub and create a stdlib equivalent of update-notifier - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var noop = require( '@stdlib/utils/noop' ); - - -// MAIN // - -/** -* Notifier constructor. -* -* @private -* @constructor -* @returns {Notifier} notifier instance -* -* @example -* var notifier = new Notifier(); -*/ -function Notifier() { - if ( !(this instanceof Notifier) ) { - return new Notifier(); - } - return this; -} - -/** -* Notifies whether a new version is available. -* -* @private -* @name notify -* @memberof Notifier.prototype -* @type {Function} -*/ -setReadOnly( Notifier.prototype, 'notify', noop ); - - -// EXPORTS // - -module.exports = Notifier; diff --git a/ctor/lib/process.js b/ctor/lib/process.js deleted file mode 100644 index d940eb6..0000000 --- a/ctor/lib/process.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; diff --git a/ctor/lib/validate.js b/ctor/lib/validate.js deleted file mode 100644 index 081806c..0000000 --- a/ctor/lib/validate.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var hasOwnProp = Object.prototype.hasOwnProperty; -var isArray = Array.isArray; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {Object} [options.pkg] - package meta information (package.json) -* @param {string} [options.version] - command-line interface version -* @param {string} [options.help] - help text -* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title -* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version -* @param {Array} [options.argv] - command-line arguments -* @param {Options} [options.options] - command-line interface options -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'pkg': {}, -* 'version': '1.0.0', -* 'help': 'Usage: beep [options] ', -* 'title': 'foo', -* 'updates': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( typeof options !== 'object' || options === null || isArray( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp.call( options, 'pkg' ) ) { - opts.pkg = options.pkg; - if ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) ); - } - } - if ( hasOwnProp.call( options, 'help' ) ) { - opts.help = options.help; - if ( typeof opts.help !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) ); - } - } - if ( hasOwnProp.call( options, 'version' ) ) { - opts.version = options.version; - if ( typeof opts.version !== 'string' ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) ); - } - } - if ( hasOwnProp.call( options, 'title' ) ) { - opts.title = options.title; - if ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) ); - } - } - if ( hasOwnProp.call( options, 'updates' ) ) { - opts.updates = options.updates; - if ( typeof opts.updates !== 'boolean' ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) ); - } - } - if ( hasOwnProp.call( options, 'argv' ) ) { - opts.argv = options.argv; - if ( !isArray( opts.argv ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) ); - } - } - if ( hasOwnProp.call( options, 'options' ) ) { - opts.options = options.options; - if ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/ctor/package.json b/ctor/package.json deleted file mode 100644 index 87ec629..0000000 --- a/ctor/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/cli/ctor", - "version": "0.0.0", - "description": "Command-line interface.", - "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", - "browser": { - "process": "process/" - }, - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utility", - "utils", - "util", - "cli", - "command-line", - "interface" - ], - "__stdlib__": { - "envs": { - "browser": false - } - } -} diff --git a/ctor/test/fixtures/stderr.js b/ctor/test/fixtures/stderr.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stderr.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/stdout.js b/ctor/test/fixtures/stdout.js deleted file mode 100644 index f1523db..0000000 --- a/ctor/test/fixtures/stdout.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Writable = require( 'stream' ).Writable; - - -// MAIN // - -/** -* Writable stream. -* -* @private -* @constructor -* @returns {Stream} Stream instance -*/ -function Stream() { - if ( !(this instanceof Stream) ) { - return new Stream(); - } - Writable.call( this ); - return this; -} - -// Create a prototype which inherits from the parent prototype: -Stream.prototype = Object.create( Writable.prototype ); - -// Set the constructor: -Stream.prototype.constructor = Stream; - -/** -* Implements the `_write` method. -* -* @private -*/ -Stream.prototype._write = function _write() { // eslint-disable-line no-underscore-dangle - // noop -}; - - -// EXPORTS // - -module.exports = Stream; diff --git a/ctor/test/fixtures/usage.txt b/ctor/test/fixtures/usage.txt deleted file mode 100644 index 779f509..0000000 --- a/ctor/test/fixtures/usage.txt +++ /dev/null @@ -1,8 +0,0 @@ - -Usage: demo [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - diff --git a/ctor/test/test.exit_code.js b/ctor/test/test.exit_code.js deleted file mode 100644 index d49cfb1..0000000 --- a/ctor/test/test.exit_code.js +++ /dev/null @@ -1,125 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var exitCode = require( './../lib/exit_code.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof exitCode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function sets the process exit code (Node.js versions >0.x.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '1.0.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process exit code (Node.js versions >0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.11.0' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the function sets the process "exit code" and forcefully exits the calling process on older Node.js versions (Node.js versions <=0.10.x)', function test( t ) { - var exitCode; - var proc; - var mock; - - mock = { - 'versions': { - 'node': '0.10.9999999' - } - }; - - exitCode = proxyquire( './../lib/exit_code.js', { - './process.js': mock - }); - - proc = { - 'exit': exit, - 'exitCode': -1 - }; - - exitCode( proc, 1 ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - - function exit( code ) { - t.ok( true, 'forcefully exits' ); - t.strictEqual( code, 1, 'sets exit code' ); - t.end(); - } -}); diff --git a/ctor/test/test.js b/ctor/test/test.js deleted file mode 100644 index 76ce280..0000000 --- a/ctor/test/test.js +++ /dev/null @@ -1,1468 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var join = require( 'path' ).join; -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var readFileSync = require( '@stdlib/fs/read-file' ).sync; -var instanceOf = require( '@stdlib/assert/instance-of' ); -var noop = require( '@stdlib/utils/noop' ); -var CLI = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// FIXTURES // - -var stdout = require( './fixtures/stdout.js' ); -var stderr = require( './fixtures/stderr.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof CLI, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - t.strictEqual( instanceOf( new CLI(), CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var ctor; - var cli; - - ctor = CLI; - cli = ctor(); - - t.strictEqual( instanceOf( cli, CLI ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor throws an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI( value ); - return cli; - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var cli = new CLI({ - 'pkg': value - }); - return cli; - }; - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stdout`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stdout(); - proc = { - 'exit': exit, - 'stdout': stream, - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'the returned instance exits the process if an error is encountered when writing to `stderr`', function test( t ) { - var stream; - var ctor; - var proc; - - stream = stderr(); - proc = { - 'exit': exit, - 'stdout': stdout(), - 'stderr': stream - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - ctor(); - stream.emit( 'error' ); - - function exit() { - t.ok( true, 'exits the process' ); - t.end(); - } -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin object)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': { - 'demo': './bin/cli' - } - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'demo', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (bin string)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0', - 'bin': './bin/cli' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true`, the returned instance sets the process title (no bin)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'beep', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `true` and insufficient package meta information is provided, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': true, - 'pkg': {} - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `title` option is a string, the returned instance sets the process title to the specified string', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': 'boop', - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, 'boop', 'sets the process title' ); - t.end(); -}); - -tape( 'if the `title` option is `false`, the returned instance does not set the process title', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'title': false, - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - } - }; - ctor( opts ); - - t.strictEqual( proc.title, '', 'does not set the process title' ); - t.end(); -}); - -tape( 'if the `updates` option is `true` and package meta data is provided, the returned instance checks for available updates in the package registry', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor', - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.ok( true, 'checks registry' ); - t.end(); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg name)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'version': '0.0.0' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg version)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'pkg': { - 'name': './../../ctor' - }, - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'if the `updates` option is `true` and insufficient package meta data is provided, the returned instance does not check for available updates in the package registry (no pkg data)', function test( t ) { - var ctor; - var proc; - var opts; - - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './notifier.js': notifier - }); - - opts = { - 'updates': true - }; - ctor( opts ); - - t.ok( true, 'is ok' ); - t.end(); - - function notifier() { - return { - 'notify': notify - }; - } - - function notify() { - t.fail( 'should never be called' ); - } -}); - -tape( 'the instance has a method which returns command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = [ 'foo', 'bar', 'baz' ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the instance has a method which returns command-line flags', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': argv - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the constructor supports providing an array of command-line arguments', function test( t ) { - var expected; - var actual; - var argv; - var ctor; - var proc; - var opts; - var cli; - - argv = [ - '/usr/local/bin/node', - 'foo.js', - 'foo', - 'bar', - '-a=b', - '--c', - 'd', - '--e', - '-f', - '-ghi', - '--beep', - 'boop', - 'baz' - ]; - argv[ '@noCallThru' ] = true; - proc = { - 'exit': noop, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false, - 'argv': argv - }; - cli = ctor( opts ); - - expected = { - 'a': 'b', - 'c': 'd', - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'beep': 'boop' - }; - actual = cli.flags(); - - t.deepEqual( actual, expected, 'returns expected flags' ); - - expected = [ - 'foo', - 'bar', - 'baz' - ]; - actual = cli.args(); - - t.deepEqual( actual, expected, 'returns expected arguments' ); - t.end(); -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-h` is set and is an alias for `--help`, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-h' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits', opts, function test( t ) { - var expected; - var actual; - var fpath; - var fopts; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - fpath = join( __dirname, 'fixtures', 'usage.txt' ); - fopts = { - 'encoding': 'utf8' - }; - expected = readFileSync( fpath, fopts ); - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--help` is set, the instance prints help text to `stderr` and exits (browser)', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = 'Usage: boop [options] '; - - actual = ''; - - opts = { - 'updates': false, - 'help': expected, - 'options': { - 'boolean': [ - 'help', - 'version' - ] - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `-V` is set and is an alias for `--version`, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '-V' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'if the flag `--version` is set, the instance prints the version to `stderr` and exits', function test( t ) { - var expected; - var actual; - var ctor; - var proc; - var opts; - var log; - - proc = { - 'exit': exit, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr(), - 'argv': [ '/usr/local/bin/node', 'foo.js', '--version' ] - }; - log = { - 'error': write - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - expected = '1.1.1'; - actual = ''; - - opts = { - 'version': '1.1.1', - 'updates': false, - 'options': { - 'boolean': [ - 'help', - 'version' - ], - 'alias': { - 'help': [ - 'h' - ], - 'version': [ - 'V' - ] - } - } - }; - ctor( opts ); - - t.strictEqual( actual, expected, 'writes expected text' ); - t.strictEqual( proc.exitCode, 0, 'sets exit code to 0' ); - t.end(); - - function write( data ) { - actual += data.toString(); - } - - function exit() { - t.fail( 'should not be called' ); - } -}); - -tape( 'the instance provides a method to forcefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit(); - - function exit( code ) { - t.strictEqual( code, 0, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance provides a method to forcefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': exit, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.exit( 5 ); - - function exit( code ) { - t.strictEqual( code, 5, 'is provided expected value' ); - t.end(); - } -}); - -tape( 'the instance method to forcefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.exit( value ); - }; - } -}); - -tape( 'the instance provides a method to gracefully exit', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close(); - - t.strictEqual( proc.exitCode, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance provides a method to gracefully exit and provide an exit code', function test( t ) { - var ctor; - var proc; - var opts; - var cli; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - cli.close( 5 ); - - t.strictEqual( proc.exitCode, 5, 'returns expected value' ); - t.end(); -}); - -tape( 'the instance method to gracefully exit throws an error if not provided a nonnegative integer', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.close( value ); - }; - } -}); - -tape( 'the instance provides a method to exit due to an error', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err ); - - t.strictEqual( proc.exitCode, 1, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance provides a method to exit due to an error (exit code)', function test( t ) { - var ctor; - var proc; - var opts; - var log; - var cli; - var err; - - proc = { - 'exit': noop, - 'exitCode': -1, - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - log = { - 'error': onError - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc, - './console.js': log - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - err = new Error( 'invalid operation' ); - cli.error( err, 2 ); - - t.strictEqual( proc.exitCode, 2, 'returns expected value' ); - t.end(); - - function onError() { - t.ok( true, 'method to log error message to `stdout` is invoked' ); - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided an error object for the first argument (exit code)', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( value, 1 ); - }; - } -}); - -tape( 'the instance method to exit due to an error throws an error if not provided a nonnegative integer as an exit code', function test( t ) { - var values; - var proc; - var ctor; - var cli; - var i; - - proc = { - 'title': '', - 'stdout': stdout(), - 'stderr': stderr() - }; - - ctor = proxyquire( './../lib/main.js', { - './process.js': proc - }); - - opts = { - 'updates': false - }; - cli = ctor( opts ); - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - cli.error( new Error( 'invalid operation' ), value ); - }; - } -}); diff --git a/ctor/test/test.validate.js b/ctor/test/test.validate.js deleted file mode 100644 index 3c8574e..0000000 --- a/ctor/test/test.validate.js +++ /dev/null @@ -1,294 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `pkg` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'pkg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `options` option which is not an object', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'options': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `argv` option which is not an array', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'argv': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `title` option which is not a string or a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'title': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `version` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'version': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `help` option which is not a string', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'help': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `updates` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'updates': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'pkg': { - 'name': 'beep', - 'version': '0.0.0' - }, - 'argv': [], - 'options': {}, - 'title': false, - 'version': '0.0.0', - 'updates': false, - 'help': 'Usage: beep [options] ' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c2dd14e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import ns = require( './index' ); - - -// TESTS // - -// The exported value is the expected interface... -{ - ns; // $ExpectType Namespace -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 6c26d3b..0000000 --- a/examples/index.js +++ /dev/null @@ -1,24 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - -console.log( objectKeys( ns ) ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc40787 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-noop@v0.2.3-esm/index.mjs";function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})})),n}function i(e){return"number"==typeof e||(!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e))}function s(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}var a="",l=!0,u="",p=!0,c=null;function f(e){return Math.floor(e)===e}var v=Object.prototype.hasOwnProperty,g=Array.isArray;var h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function d(){throw new Error("setTimeout has not been defined")}function m(){throw new Error("clearTimeout has not been defined")}var b=d,y=m;function w(e){if(b===setTimeout)return setTimeout(e,0);if((b===d||!b)&&setTimeout)return b=setTimeout,setTimeout(e,0);try{return b(e,0)}catch(t){try{return b.call(null,e,0)}catch(t){return b.call(this,e,0)}}}"function"==typeof h.setTimeout&&(b=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var k,j=[],T=!1,E=-1;function O(){T&&k&&(T=!1,k.length?j=k.concat(j):E=-1,j.length&&_())}function _(){if(!T){var e=w(O);T=!0;for(var t=j.length;t;){for(k=j,j=[];++E1)for(var n=1;n0||n[1]>10?e.exitCode=t:(e.exitCode=t,setTimeout((function(){e.exit(t)}),10))}function re(){return this instanceof re?this:new re}n(re.prototype,"notify",o);var ie=function(e,t){t||(t={});var n={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(n.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?n.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){n.bools[e]=!0}));var o={};function r(e){return o[e].some((function(e){return n.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){n.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){n.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function u(e,t,o){for(var r=e,i=0;i1){if("number"!=typeof n||!f(n)||n<0)throw new TypeError(t("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",n));o=n}else o=1;te.error("Error: %s",e.message),oe(ee,o)})),le(ue.prototype,"exit",(function(e){if(0===arguments.length)return ee.exit(0);if("number"!=typeof e||!f(e)||e<0)throw new TypeError(t("invalid argument. Must provide a nonnegative integer. Value: `%s`.",e));ee.exit(e)}));var pe={};e(pe,"CLI",ue);export{ue as CLI,pe as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..af99b2d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../node_modules/minimist/index.js","../ctor/lib/is_integer.js","../ctor/lib/validate.js","../ctor/lib/process.js","../ctor/lib/console.js","../ctor/lib/exit_code.js","../ctor/lib/notifier.js","../ctor/lib/main.js","../lib/index.js"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Tests if a finite double-precision floating-point number is an integer.\n*\n* @private\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\t// NOTE: we explicitly avoid using `@stdlib/math/base/special` here in order to avoid circular dependencies.\n\treturn ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nexport default isInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport format from '@stdlib/string/format';\n\n\n// VARIABLES //\n\nvar hasOwnProp = Object.prototype.hasOwnProperty;\nvar isArray = Array.isArray;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {Object} [options.pkg] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help] - help text\n* @param {(string|boolean)} [options.title] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options] - command-line interface options\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'pkg': {},\n* 'version': '1.0.0',\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( typeof options !== 'object' || options === null || isArray( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp.call( options, 'pkg' ) ) {\n\t\topts.pkg = options.pkg;\n\t\tif ( typeof opts.pkg !== 'object' || opts.pkg === null || isArray( opts.pkg ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an object. Option: `%s`.', 'pkg', opts.pkg ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'help' ) ) {\n\t\topts.help = options.help;\n\t\tif ( typeof opts.help !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'help', opts.help ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'version' ) ) {\n\t\topts.version = options.version;\n\t\tif ( typeof opts.version !== 'string' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'version', opts.version ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'title' ) ) {\n\t\topts.title = options.title;\n\t\tif ( typeof opts.title !== 'string' && typeof opts.title !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be either a string or boolean primitive. Option: `%s`.', 'title', opts.title ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'updates' ) ) {\n\t\topts.updates = options.updates;\n\t\tif ( typeof opts.updates !== 'boolean' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'updates', opts.updates ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'argv' ) ) {\n\t\topts.argv = options.argv;\n\t\tif ( !isArray( opts.argv ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'argv', opts.argv ) );\n\t\t}\n\t}\n\tif ( hasOwnProp.call( options, 'options' ) ) {\n\t\topts.options = options.options;\n\t\tif ( typeof opts.options !== 'object' || opts.options === null || isArray( opts.options ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a plain object. Option: `%s`.', 'options', opts.options ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar proc = require( 'process' );\n\n\n// EXPORTS //\n\nexport default proc;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// EXPORTS //\n\nexport default console;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2019 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport proc from './process.js';\n\n\n// VARIABLES //\n\nvar NODE_VERSION = proc.versions.node;\nvar TIMEOUT = 10; // ms\n\n\n// MAIN //\n\n/**\n* Sets the process exit code.\n*\n* @private\n* @param {Object} proc - process object\n* @param {NonNegativeInteger} code - exit code\n* @returns {void}\n*/\nfunction exitCode( proc, code ) {\n\tvar v;\n\n\t// Handle old Node.js versions lacking `process.exitCode` support...\n\tv = NODE_VERSION.split( '.' );\n\tv[ 0 ] = parseInt( v[ 0 ], 10 );\n\tv[ 1 ] = parseInt( v[ 1 ], 10 );\n\n\t// Case: >0.x.x\n\tif ( v[ 0 ] > 0 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: >0.10.x\n\tif ( v[ 1 ] > 10 ) {\n\t\tproc.exitCode = code;\n\t\treturn;\n\t}\n\t// Case: <= 0.10.x\n\tproc.exitCode = code; // NOTE: assigning this property should have no operational effect in older Node.js versions\n\n\t// No choice but to forcefully exit during a subsequent turn of the event loop (note: the timeout duration is arbitrary; the main idea is to hopefully allow the event loop queue to drain before exiting the process, including the flushing of stdio streams which can be non-blocking/asynchronous)...\n\tsetTimeout( onTimeout, TIMEOUT );\n\n\t/**\n\t* Callback invoked during a subsequent turn of the event loop.\n\t*\n\t* @private\n\t*/\n\tfunction onTimeout() {\n\t\tproc.exit( code );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default exitCode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n// FIXME: remove this stub and create a stdlib equivalent of update-notifier\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-nonenumerable-read-only-property';\nimport noop from '@stdlib/utils/noop';\n\n\n// MAIN //\n\n/**\n* Notifier constructor.\n*\n* @private\n* @constructor\n* @returns {Notifier} notifier instance\n*\n* @example\n* var notifier = new Notifier();\n*/\nfunction Notifier() {\n\tif ( !(this instanceof Notifier) ) {\n\t\treturn new Notifier();\n\t}\n\treturn this;\n}\n\n/**\n* Notifies whether a new version is available.\n*\n* @private\n* @name notify\n* @memberof Notifier.prototype\n* @type {Function}\n*/\nsetReadOnly( Notifier.prototype, 'notify', noop );\n\n\n// EXPORTS //\n\nexport default Notifier;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable stdlib/jsdoc-doctest, no-restricted-syntax */\n\n'use strict';\n\n// MODULES //\n\nvar parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent\nimport format from '@stdlib/string/format';\nimport defaults from './defaults.json';\nimport isInteger from './is_integer.js';\nimport validate from './validate.js';\nimport proc from './process.js';\nimport log from './console.js';\nimport exitCode from './exit_code.js';\nimport notifier from './notifier.js';\n\n\n// VARIABLES //\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies. This should not be problematic as (1) this package is unlikely to be used outside of Node.js and, thus, in environments lacking support for the built-in APIs, and (2) most of the historical bugs for the respective APIs were in environments such as IE and not the versions of V8 included in Node.js >= v0.10.x.\nvar defineProperty = Object.defineProperty;\nvar objectKeys = Object.keys;\n\n\n// FUNCTIONS //\n\n/**\n* Defines a read-only non-enumerable property.\n*\n* @private\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// MAIN //\n\n/**\n* Command-line interface constructor.\n*\n* @constructor\n* @param {Options} [options] - options\n* @param {Object} [options.pkg={}] - package meta information (package.json)\n* @param {string} [options.version] - command-line interface version\n* @param {string} [options.help=\"\"] - help text\n* @param {(string|boolean)} [options.title=true] - process title or a boolean indicating whether to set the process title\n* @param {boolean} [options.updates=true] - boolean indicating whether to check if a command-line interface is an outdated version\n* @param {Array} [options.argv] - command-line arguments\n* @param {Options} [options.options={}] - command-line interface options\n* @throws {TypeError} must provide an object\n* @throws {TypeError} must provide valid options\n* @returns {CLI} command-line interface\n*\n* @example\n* var opts = {\n* 'pkg': require( './path/to/package.json' ),\n* 'help': 'Usage: beep [options] ',\n* 'title': 'foo',\n* 'updates': true,\n* 'options': {\n* 'boolean': [\n* 'help',\n* 'version'\n* ]\n* }\n* };\n* var cli = new CLI( opts );\n* // returns \n*\n* cli.close();\n*/\nfunction CLI( options ) {\n\tvar nopts;\n\tvar flags;\n\tvar keys;\n\tvar opts;\n\tvar argv;\n\tvar args;\n\tvar self;\n\tvar err;\n\tif ( !( this instanceof CLI ) ) {\n\t\tif ( arguments.length ) {\n\t\t\treturn new CLI( options );\n\t\t}\n\t\treturn new CLI();\n\t}\n\topts = {\n\t\t'pkg': {},\n\t\t'help': defaults.help,\n\t\t'title': defaults.title,\n\t\t'version': defaults.version,\n\t\t'updates': defaults.updates,\n\t\t'argv': defaults.argv,\n\t\t'options': {}\n\t};\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tself = this;\n\n\t// Force the process to exit if an error is encountered when writing to `stdout` or `stderr`:\n\tproc.stdout.on( 'error', proc.exit );\n\tproc.stderr.on( 'error', proc.exit );\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @name args\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {StringArray} parsed command-line arguments\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var args = cli.args();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'args', getArgs );\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @name flags\n\t* @memberof CLI#\n\t* @type {Function}\n\t* @returns {Object} parsed command-line flags\n\t*\n\t* @example\n\t* var cli = new CLI();\n\t*\n\t* var flags = cli.flags();\n\t* // returns \n\t*/\n\tsetReadOnly( this, 'flags', getFlags );\n\n\t/**\n\t* Prints usage information and exits the process.\n\t*\n\t* @name help\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'help': 'Usage: beep [options] '\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.help();\n\t* // => 'Usage: beep [options] '\n\t*/\n\tsetReadOnly( this, 'help', help );\n\n\t/**\n\t* Prints the command-line interface version and exits the process.\n\t*\n\t* @name version\n\t* @memberof CLI#\n\t* @type {Function}\n\t*\n\t* @example\n\t* var opts = {\n\t* 'pkg': require( './path/to/package.json' )\n\t* };\n\t* var cli = new CLI( opts );\n\t*\n\t* cli.version();\n\t* // => '#.#.#'\n\t*/\n\tsetReadOnly( this, 'version', version );\n\n\t// Check whether to set the process title...\n\tif ( opts.title === true && opts.pkg ) {\n\t\tif ( typeof opts.pkg.bin === 'object' && opts.pkg.bin !== null ) {\n\t\t\tkeys = objectKeys( opts.pkg.bin );\n\n\t\t\t// Note: we don't have a way of knowing which command name in the `bin` hash was invoked; thus, we assume the first entry.\n\t\t\tproc.title = keys[ 0 ];\n\t\t} else if ( opts.pkg.name ) {\n\t\t\tproc.title = opts.pkg.name;\n\t\t}\n\t} else if ( opts.title ) {\n\t\tproc.title = opts.title;\n\t}\n\t// Check whether to notify the user of a new CLI version...\n\tif ( opts.updates && opts.pkg && opts.pkg.name && opts.pkg.version ) {\n\t\tnopts = {\n\t\t\t'pkg': opts.pkg\n\t\t};\n\t\tnotifier( nopts ).notify();\n\t}\n\t// Determine the command-line interface version...\n\tif ( !opts.version && opts.pkg && opts.pkg.version ) {\n\t\topts.version = opts.pkg.version;\n\t}\n\t// Parse command-line arguments:\n\tif ( opts.argv ) {\n\t\topts.argv = opts.argv.slice( 2 );\n\t} else {\n\t\topts.argv = proc.argv.slice( 2 );\n\t}\n\targv = parseArgs( opts.argv, opts.options );\n\n\t// Cache parsed arguments:\n\targs = argv._;\n\tdelete argv._;\n\tflags = argv;\n\n\t// Determine whether to print help text...\n\tif ( flags.help ) {\n\t\treturn this.help( 0 );\n\t}\n\t// Determine whether to print the version...\n\tif ( flags.version ) {\n\t\treturn this.version();\n\t}\n\treturn this;\n\n\t/**\n\t* Returns parsed command-line arguments.\n\t*\n\t* @private\n\t* @returns {StringArray} parsed command-line arguments\n\t*/\n\tfunction getArgs() {\n\t\treturn args.slice();\n\t}\n\n\t/**\n\t* Returns parsed command-line flags.\n\t*\n\t* @private\n\t* @returns {Object} parsed command-line flags\n\t*/\n\tfunction getFlags() {\n\t\tvar keys;\n\t\tvar o;\n\t\tvar k;\n\t\tvar i;\n\n\t\tkeys = objectKeys( flags );\n\t\to = {};\n\t\tfor ( i = 0; i < keys.length; i++ ) {\n\t\t\tk = keys[ i ];\n\t\t\to[ k ] = flags[ k ];\n\t\t}\n\t\treturn o;\n\t}\n\n\t/**\n\t* Prints usage information.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing usage information, the function forces the process to exit.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [code=0] - exit code\n\t*/\n\tfunction help( code ) {\n\t\tlog.error( opts.help );\n\t\tself.close( code || 0 );\n\t}\n\n\t/**\n\t* Prints the command-line interface version.\n\t*\n\t* ## Notes\n\t*\n\t* - Upon printing the version, the function forces the process to exit.\n\t*\n\t* @private\n\t*/\n\tfunction version() {\n\t\tlog.error( opts.version );\n\t\tself.close();\n\t}\n}\n\n/**\n* Gracefully exits the command-line interface and the calling process.\n*\n* @name close\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Gracefully exit:\n* cli.close();\n*/\nsetReadOnly( CLI.prototype, 'close', function close( code ) {\n\tif ( arguments.length === 0 ) {\n\t\texitCode( proc, 0 );\n\t\treturn;\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\texitCode( proc, code );\n});\n\n/**\n* Exits the command-line interface and the calling process due to an error.\n*\n* ## Notes\n*\n* - The value assigned to the `message` property of the provided `Error` object is printed to `stderr` prior to exiting the command-line interface and the calling process.\n*\n* @name error\n* @memberof CLI.prototype\n* @type {Function}\n* @param {Error} error - error object\n* @param {NonNegativeInteger} [code=1] - exit code\n* @throws {TypeError} first argument must be an error object\n* @throws {TypeError} second argument must be a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // ...\n*\n* // Create an error object:\n* var err = new Error( 'invalid operation' );\n*\n* // Exit the process:\n* cli.error( err, 0 );\n*/\nsetReadOnly( CLI.prototype, 'error', function onError( error, code ) {\n\tvar c;\n\tif ( !( error instanceof Error ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an error object. Value: `%s`.', error ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', code ) );\n\t\t}\n\t\tc = code;\n\t} else {\n\t\tc = 1;\n\t}\n\tlog.error( 'Error: %s', error.message );\n\texitCode( proc, c );\n});\n\n/**\n* Forces the command-line interface (and the calling process) to exit.\n*\n* @name exit\n* @memberof CLI.prototype\n* @type {Function}\n* @param {NonNegativeInteger} [code=0] - exit code\n* @throws {TypeError} must provide a nonnegative integer\n* @returns {void}\n*\n* @example\n* var cli = new CLI();\n*\n* // Forcefully exit:\n* cli.exit();\n*/\nsetReadOnly( CLI.prototype, 'exit', function exit( code ) {\n\tif ( arguments.length === 0 ) {\n\t\treturn proc.exit( 0 );\n\t}\n\tif ( typeof code !== 'number' || !isInteger( code ) || code < 0 ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a nonnegative integer. Value: `%s`.', code ) );\n\t}\n\tproc.exit( code );\n});\n\n\n// EXPORTS //\n\nexport default CLI;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/*\n* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils/define-read-only-property';\n\n\n// MAIN //\n\n/**\n* Top-level namespace.\n*\n* @namespace ns\n*/\nvar ns = {};\n\n/**\n* @name CLI\n* @memberof ns\n* @readonly\n* @type {Function}\n* @see {@link module:@stdlib/cli/ctor}\n*/\nimport CLI from './../ctor';\nsetReadOnly( ns, 'CLI', CLI );\n\n\n// EXPORTS //\n\nexport default ns;\n"],"names":["isNumber","x","test","isConstructorOrProto","obj","key","isInteger","Math","floor","hasOwnProp","Object","prototype","hasOwnProperty","isArray","Array","proc","log","console","NODE_VERSION","versions","node","exitCode","code","v","split","parseInt","setTimeout","exit","Notifier","this","setReadOnly","noop","parseArgs","args","opts","flags","bools","strings","unknownFn","unknown","boolean","allBools","concat","filter","Boolean","forEach","aliases","aliasIsBoolean","some","keys","alias","y","string","k","defaults","default","argv","_","setKey","value","o","i","length","undefined","Number","String","lastKey","push","setArg","val","arg","argDefined","notFlags","indexOf","slice","next","m","match","letters","broken","j","stopEarly","apply","defineProperty","objectKeys","prop","configurable","enumerable","writable","CLI","options","self","err","arguments","pkg","help","title","version","updates","TypeError","format","call","validate","stdout","on","stderr","error","close","bin","name","notifier","notify","c","Error","message","ns"],"mappings":";;i1BAYA,SAASA,EAASC,GACjB,MAAiB,iBAANA,MACP,iBAAmBC,KAAKD,IACrB,6CAA+CC,KAAKD,GAC5D,CAEA,SAASE,EAAqBC,EAAKC,GAClC,MAAgB,gBAARA,GAA6C,mBAAbD,EAAIC,IAAgC,cAARA,CACrE,CAEA,+BCeA,SAASC,EAAWL,GAEnB,OAASM,KAAKC,MAAOP,KAAQA,CAC9B,CCbA,IAAIQ,EAAaC,OAAOC,UAAUC,eAC9BC,EAAUC,MAAMD,ggECNhBE,gRCAJC,GAAeC,QCKXC,GAAeH,GAAKI,SAASC,KAcjC,SAASC,GAAUN,EAAMO,GACxB,IAAIC,GAGJA,EAAIL,GAAaM,MAAO,MACrB,GAAMC,SAAUF,EAAG,GAAK,IAC3BA,EAAG,GAAME,SAAUF,EAAG,GAAK,IAGtBA,EAAG,GAAM,GAKTA,EAAG,GAAM,GAJbR,EAAKM,SAAWC,GASjBP,EAAKM,SAAWC,EAGhBI,YAOA,WACCX,EAAKY,KAAML,EACX,GA5CY,IA6Cd,CCjCA,SAASM,KACR,OAAOC,gBAAgBD,GAGhBC,KAFC,IAAID,EAGb,CAUAE,EAAaF,GAASjB,UAAW,SAAUoB,GC/B3C,IAAIC,GPFa,SAAUC,EAAMC,GAC3BA,IAAQA,EAAO,CAAE,GAEtB,IAAIC,EAAQ,CACXC,MAAO,CAAE,EACTC,QAAS,CAAE,EACXC,UAAW,MAGgB,mBAAjBJ,EAAKK,UACfJ,EAAMG,UAAYJ,EAAKK,SAGI,kBAAjBL,EAAKM,SAAyBN,EAAKM,QAC7CL,EAAMM,UAAW,EAEjB,GAAGC,OAAOR,EAAKM,SAASG,OAAOC,SAASC,SAAQ,SAAUxC,GACzD8B,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EAAI,CAC3B,GAAqB,iBAATxC,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,gFAAiF9E,IAE/G0F,EAAI1F,CACN,MACE0F,EAAI,EAELhG,GAAI0F,MAAO,YAAaA,EAAMQ,SAC9B7F,GAAUN,GAAMiG,EACjB,IAkBAlF,GAAa2D,GAAI9E,UAAW,QAAQ,SAAeW,GAClD,GAA0B,IAArBuE,UAAU/B,OACd,OAAO/C,GAAKY,KAAM,GAEnB,GAAqB,iBAATL,IAAsBhB,EAAWgB,IAAUA,EAAO,EAC7D,MAAM,IAAI6E,UAAWC,EAAQ,qEAAsE9E,IAEpGP,GAAKY,KAAML,EACZ,IC5XA,IAAA6F,GAAA,CAAA,EAUArF,EAAAqF,GAAA,MAAA1B","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index ecb60a1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* -* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name. -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); - - -// MAIN // - -/** -* Top-level namespace. -* -* @namespace ns -*/ -var ns = {}; - -/** -* @name CLI -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/cli/ctor} -*/ -setReadOnly( ns, 'CLI', require( './../ctor' ) ); - - -// EXPORTS // - -module.exports = ns; diff --git a/package.json b/package.json index a67f185..e750ef2 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,8 @@ "version": "0.3.3", "description": "Command-line interface.", "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": { - "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", @@ -35,36 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/string": "github:stdlib-js/string#main", - "@stdlib/utils": "github:stdlib-js/utils#main", - "minimist": "^1.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert": "github:stdlib-js/assert#main", - "@stdlib/bench": "github:stdlib-js/bench#main", - "@stdlib/fs": "github:stdlib-js/fs#main", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", @@ -79,4 +27,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7bf18bf --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e682e93..0000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.strictEqual( keys.length > 0, true, 'has keys' ); - t.end(); -});